This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
177 lines (170 loc) · 5.4 KB
/
content.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
var ISIS_PATTERN = new RegExp('(ISIS)|(ISIL)|(Islamic State)|(Isis)|(Isil)', 'g')
var HILL_PATTERN = new RegExp('(Hillary Clinton)|(Hillary Rodham Clinton)|(Mrs\. Clinton)', 'g')
var FAKENEWS_PATTERN = new RegExp('(MSNBC)|(NBC)|(NYTIMES)|(NYTimes)|(TNYT)|(NYT)|(New York Times)|(NBC News)|(HuffPo)|(Huffington Post)|(ABC News)|(American Broadcasting Company)|(CBS)', 'g')
var CNN_PATTERN = new RegExp('CNN', 'g')
var CRUZ_PATTERN = new RegExp('Ted Cruz', 'g')
var MARCO_PATTERN = new RegExp('(Marco Rubio)|(Rubio)', 'g')
var JEB_PATTERN = new RegExp('(Jeb Bush)|(Jeb)', 'g')
var WARREN_PATTERN = new RegExp('Elizabeth Warren', 'g')
var KIM_JONG_UN_PATTERN = new RegExp('(Kim Jong-un)|(Kim Jong Un)', 'g')
var BIDEN_PATTERN = new RegExp('Joe Biden', 'g')
var LAMB_PATTERN = new RegExp('Conor Lamb', 'g')
var BANNON_PATTERN = new RegExp('Steve Bannon', 'g')
var DURBIN_PATTERN = new RegExp('Dick Durbin', 'g')
var FEINSTEIN_PATTERN = new RegExp('Dianne Feinstein', 'g')
var FLAKE_PATTERN = new RegExp('Jeff Flake', 'g')
var FRANKEN_PATTERN = new RegExp('Al Franken', 'g')
var CORKER_PATTERN = new RegExp('Bob Corker', 'g')
var KELLY_PATTERN = new RegExp('Megyn Kelly', 'g')
var SCARBOROUGH_PATTERN = new RegExp('Joe Scarborough', 'g')
var MIKA_PATTERN = new RegExp('Mika Brzezinski', 'g')
var CHUCK_TODD_PATTERN = new RegExp('Chuck Todd', 'g')
var JIM_ACOSTA_PATTERN = new RegExp('Jim Acosta', 'g')
var CHUCK_SCHUMER_PATTERN = new RegExp('Chuck Schumer', 'g')
var BERNIE_PATTERN = new RegExp('Bernie Sanders', 'g')
var KASICH_PATTERN = new RegExp('John Kasich', 'g')
var ASSAD_PATTERN = new RegExp('Bashar (Hafez)? al-Assad', 'g')
var COFFEE_PATTERN = new RegExp('(coffee)|(Coffee)', 'g')
chrome.storage.sync.get(null, function(obj) {
walk(document.body)
})
// Credit to t-j-crowder on StackOverflow for this walk function
// http://bit.ly/1o47R7V
function walk(node) {
var child, next
switch (node.nodeType) {
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild
while (child) {
next = child.nextSibling
walk(child)
child = next
}
break
case 3: // Text node
convert(node)
break
}
}
function convert(textNode) {
var mappings = buildTrumpMap()
var mapKeys = Object.keys(mappings)
mapKeys.forEach(function (key) {
textNode.nodeValue = textNode.nodeValue.replace(mappings[key].regex, mappings[key].nick)
})
}
// Build RegEx patterns and replacements for each object of Trump's derision
function buildTrumpMap () {
return {
"cnn": {
"regex": CNN_PATTERN,
"nick": "Clinton News Network"
},
"kasich": {
"regex": KASICH_PATTERN,
"nick": "1 for 38 Kasich"
},
"bernie": {
"regex": BERNIE_PATTERN,
"nick": "Crazy Bernie"
},
"isis": {
"regex": ISIS_PATTERN,
"nick": "Evil Losers"
},
"hillary": {
"regex": HILL_PATTERN,
"nick": "Crooked Hillary"
},
"fakenews": {
"regex": FAKENEWS_PATTERN,
"nick": "Fake News"
},
"cruz": {
"regex": CRUZ_PATTERN,
"nick": "Lyin' Ted"
},
"marco": {
"regex": MARCO_PATTERN,
"nick": "Little Marco"
},
"jeb": {
"regex": JEB_PATTERN,
"nick": "Low Energy Jeb"
},
"warren": {
"regex": WARREN_PATTERN,
"nick": "Goofy Pocahontas"
},
"kimjongun": {
"regex": KIM_JONG_UN_PATTERN,
"nick": "Little Rocket Man"
},
"biden": {
"regex": BIDEN_PATTERN,
"nick": "Crazy Joe Biden"
},
"lamb": {
"regex": LAMB_PATTERN,
"nick": "Lamb the Sham"
},
"bannon": {
"regex": BANNON_PATTERN,
"nick": "Sloppy Steve"
},
"durbin": {
"regex": DURBIN_PATTERN,
"nick": "Dicky Durbin"
},
"feinstein": {
"regex": FEINSTEIN_PATTERN,
"nick": "Sneaky Dianne Feinstein"
},
"flake": {
"regex": FLAKE_PATTERN,
"nick": "Jeff Flakey"
},
"franken": {
"regex": FRANKEN_PATTERN,
"nick": "Al Frankenstein"
},
"corker": {
"regex": CORKER_PATTERN,
"nick": "Liddle' Bob Corker"
},
"kelly": {
"regex": KELLY_PATTERN,
"nick": "Crazy Megyn"
},
"scarborough": {
"regex": SCARBOROUGH_PATTERN,
"nick": "Psycho Joe"
},
"mika": {
"regex": MIKA_PATTERN,
"nick": "Dumb as a Rock Mika"
},
"chucktodd": {
"regex": CHUCK_TODD_PATTERN,
"nick": "Sleepy Eyes Chuck Todd"
},
"jimacosta": {
"regex": JIM_ACOSTA_PATTERN,
"nick": "Crazy Jim Acosta"
},
"chuckschumer": {
"regex": CHUCK_SCHUMER_PATTERN,
"nick": "Cryin' Chuck Schumer"
},
"coffee": {
"regex": COFFEE_PATTERN,
"nick": "covfefe"
},
"assad": {
"regex": ASSAD_PATTERN,
"nick": "Animal Assad"
}
}
}