forked from zhast/Memeify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaprilfools.js
145 lines (122 loc) · 6.38 KB
/
aprilfools.js
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Huge credit to "Make America Kittens Again"
*/
var blacklist = ["trump"];
chrome.storage.local.get({
blockPence: false,
blockFarage: false,
blockLePen: false,
blockWilders: false,
blockBannon: false
}, function (items) {
if (items.blockPence) {
blacklist.push("mike pence");
};
if (items.blockFarage) {
blacklist.push("isis");
};
if (items.blockLePen) {
blacklist.push("xenophobia");
};
if (items.blockWilders) {
blacklist.push("hate");
};
if (items.blockBannon) {
blacklist.push("nsfw");
};
document.addEventListener('DOMContentLoaded', meme(memeList), false);
});
var memeList = {
"kitten": [
{ "file": "1.jpg", "Credit": "Crsan", "URL": "http://i.imgur.com/UIB2UE4.png", "type": "0" },
{ "file": "2.jpg", "Credit": "Abcrumley", "URL": "https://s-media-cache-ak0.pinimg.com/236x/11/b4/20/11b420fbf1595be3056ad6355277933c.jpg", "type": "0" },
{ "file": "3.jpg", "Credit": "Woodchild2010", "URL": "https://s-media-cache-ak0.pinimg.com/originals/35/dd/a7/35dda730657b0adc60be17ae856e9a0a.jpg", "type": "0" },
{ "file": "4.jpg", "Credit": "Vancouverfilmschool", "URL": "http://i3.cpcache.com/product/376541894/javascript_coffee_mug.jpg?side=Back&color=White&height=460&width=460&qv=90", "type": "0" },
{ "file": "5.jpg", "Credit": "Jameswragg", "URL": "http://lh6.ggpht.com/-tqTOdp-mP6w/UZEWXAEE0JI/AAAAAAAAAv0/dwDaFn8rtq8/s1600-h/lol_programming%25255B3%25255D.jpg", "type": "0" },
{ "file": "6.jpg", "Credit": "Eva101", "URL": "https://s-media-cache-ak0.pinimg.com/236x/e6/bf/0c/e6bf0cf566a8279c2b3c8c4ae7188a7a.jpg", "type": "0" },
{ "file": "7.jpg", "Credit": "Pinguino", "URL": "https://s-media-cache-ak0.pinimg.com/236x/8c/9a/cd/8c9acddb7725865128cc4eda3e289ca8.jpg", "type": "0" },
{ "file": "8.jpg", "Credit": "Daisyree Bakker", "URL": "https://s-media-cache-ak0.pinimg.com/236x/67/d3/79/67d37913081dfcdf0a1c002f3745b278.jpg", "type": "0" },
{ "file": "9.jpg", "Credit": "VictoriaPeckham", "URL": "http://www.flickr.com/photos/victoriapeckham/4000992556/", "type": "0" },
{ "file": "10.jpg", "Credit": "Jameswragg", "URL": "http://lh6.ggpht.com/-tqTOdp-mP6w/UZEWXAEE0JI/AAAAAAAAAv0/dwDaFn8rtq8/s1600-h/lol_programming%25255B3%25255D.jpg", "type": "0" },
{ "file": "11.jpg", "Credit": "Eva101", "URL": "https://s-media-cache-ak0.pinimg.com/236x/e6/bf/0c/e6bf0cf566a8279c2b3c8c4ae7188a7a.jpg", "type": "0" },
{ "file": "12.jpg", "Credit": "Pinguino", "URL": "https://s-media-cache-ak0.pinimg.com/236x/8c/9a/cd/8c9acddb7725865128cc4eda3e289ca8.jpg", "type": "0" },
{ "file": "13.jpg", "Credit": "Daisyree Bakker", "URL": "https://s-media-cache-ak0.pinimg.com/236x/67/d3/79/67d37913081dfcdf0a1c002f3745b278.jpg", "type": "0" },
{ "file": "14.jpg", "Credit": "VictoriaPeckham", "URL": "http://www.flickr.com/photos/victoriapeckham/4000992556/", "type": "0" }
]
};
function meme(memeList) {
// called on page load. Searches all img alt text and srcs for the strings in blacklist, replaces with kittens
var pagepics = document.getElementsByTagName("img"), i = 0, img;
while (img = pagepics[i++]) {
if (img.hasAttribute('replaced')) {
// already replaced
}
else {
// not yet replaced
var alttext = String(img.alt).toLowerCase();
var imgsrc = String(img.src).toLowerCase();
if (img.parentElement.nodeName != 'BODY') {
// check parent innerHTML for blackilist
var parenttag = img.parentElement.innerHTML.toLowerCase();
}
else {
// prevent parse of entire doc
var parenttag = '';
};
var imgwidth = img.clientWidth;
var imgheight = img.clientHeight;
blacklist.forEach(function (blist) {
if ((alttext.indexOf(blist) != -1) || (imgsrc.indexOf(blist) != -1) || (parenttag.indexOf(blist) != -1)) {
// append old src
img.setAttribute("replaced", img.src);
// remove srcsets, forcing browser to the kitten - eg, BBC News
if (img.hasAttribute('srcset')) {
img.removeAttribute('srcset');
};
// remove source srcsets if children of same parent <picture> element - eg, the Guardian
if (img.parentElement.nodeName == 'PICTURE') {
var theparent = img.parentNode;
for (var child = theparent.firstChild; child !== null; child = child.nextSibling) {
if (child.nodeName == "SOURCE") {
child.removeAttribute('src');
child.removeAttribute('srcset');
};
};
};
// knock out lazyloader data URLs so it doesn't overwrite kittens
if (img.hasAttribute('data-src')) {
img.removeAttribute('data-src');
};
if (img.hasAttribute('data-hi-res-src')) {
img.removeAttribute('data-hi-res-src');
};
if (img.hasAttribute('data-low-res-src')) {
img.removeAttribute('data-low-res-src');
};
// main replacement here
var randk = Math.floor(Math.random() * 13) + 1
img.src = 'https://raw.githubusercontent.com/Steven-19/Memeify/master/Programming%20Memes/' + memeList.kitten[randk].file + '';
img.width = imgwidth;
img.height = imgheight;
memeReplacements++;
};
});
};
}
};
// function to replace memed-images with the original SRCs
function undomeme() {
var pagepics = document.getElementsByTagName("img"), i = 0, img;
while (img = pagepics[i++]) {
if (img.hasAttribute('replaced')) {
img.src = img.getAttribute('replaced');
img.removeAttribute('replaced');
};
};
}
// listener for context menu click invoking the above
chrome.extension.onMessage.addListener(function (message, sender, callback) {
if (message.functiontoInvoke == "undoMayMays") {
undomeme();
};
});