-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook.js
More file actions
113 lines (99 loc) · 2.53 KB
/
Copy pathfacebook.js
File metadata and controls
113 lines (99 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//Adds support for iterating over HTMLCollections with for of and for in
HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
const emojis = {
"baby": "🍼",
"beach": "🏖",
"beard": "👴",
"bicycle": "🚲",
"camera": "📷",
"car": "🚗",
"child": "👦",
"christmas tree": "🎄",
"closeup": "👀",
"cloud": "☁️",
"crowd": "👥",
"dog": "🐶",
"drink": "🍹",
"eating": "🍽",
"eyeglasses": "👓",
"flower": "🌻",
"food": "🍎",
"golf": "🏌️",
"grass": "🍃",
"hat": "👒",
"indoor": "🏠",
"living room": "🏠",
"meme": "👍",
"mountain": "🌋",
"nature": "🏞",
"night": "🌃",
"ocean": "🌊",
"office": "💼",
"outdoor": "🚵",
"eating": "🍽",
"sitting": "💺",
"smiling": "😂",
"standing": "🕴",
"phone": "📱",
"plant": "🌿",
"selfie": "🤳",
"shoes": "👡",
"sitting": "💺",
"sky": "☀️",
"skyscraper": "🏙",
"sleeping": "😴",
"smiling": "😋",
"snow": "❄️",
"standing": "🕴",
"stripes": "📶",
"suit": "🕴",
"sunglasses": "🕶",
"swimming": "🏊",
"table": "🍽",
"text": "🔠",
"tree": "🌴",
"twilight": "🌃",
"water": "💧",
"glasses": "👓",
"instrument": "🎸",
"stage": "🎭",
"fireworks": "🎆",
"pizza": "🍕",
"taco": "🌮",
"burrito": "🌯",
"burger": "🍔",
"hotdog": "🌭",
"pizza": "🍕",
"close-up": "🔎",
"person": "👤",
"people": "👥",
}
function addComputerVisionTags() {
const TAG_PREFIX = "Image may contain: ";
const newImgs = [...document.getElementsByTagName('img')].filter(img => img.getAttribute("data-prev-alt") !== img.getAttribute("alt"));
for(var img of newImgs) {
//Remember that we've added the tags to this image
img.setAttribute("data-prev-alt", img.alt);
if(img.alt.startsWith(TAG_PREFIX)) {
const tags = img.alt.slice(TAG_PREFIX.length).split(/, | and /);
var html = "<ul class='computer-vision'>";
html += "<li><b>Image may contain</b></li>";
for(var tag of tags) {
let prefix = "";
//Match an emoji prefix
prefix = emojis[Object.keys(emojis).find(k => tag.includes(k))] || "";
html += `<li>${prefix} ${tag}</li>`;
}
html += "</ul>";
img.style.position = 'relative';
img.insertAdjacentHTML('afterend', html);
}
}
};
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
addComputerVisionTags();
});
});
observer.observe(document.body, { attributes: true, childList: true, characterData: false });
addComputerVisionTags();