-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
688 lines (656 loc) · 16.9 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
//console.log("content.js is Running");
var alertActive = false;
var lastMutationSearch = new Date(Date.now());
lastMutationSearch = new Date(lastMutationSearch.getTime() - 1000*10);
//Search for Words That Might be Spoilers
( function main () {
function EventHub ( hub_name ) {
var private = {
events: {},
add_one: function ( name, observer ) {
if ( typeof private.events[ name ] === 'undefined' ) {
private.events[ name ] = [];
}
private.events[ name ].push( observer );
},
remove: function ( name ) {
private.events[ name ] = undefined;
}
};
var public = {
add: function ( observers ) {
Object.keys( observers ).forEach( function ( name ) {
private.add_one(name, observers[name]);
});
},
fire: function ( name, data ) {
if ( typeof private.events[ name ] !== 'undefined' ) {
private.events[ name ].forEach( function ( observer ) {
observer(data);
});
};
},
stop: function () {
public.fire = function () {}
}
};
return public;
};
function Scanner () {
var public = {
get_matches_amount: function ( text, phrases ) {
var matches_amount = 0;
text = text.toLowerCase();
phrases.forEach( function ( phrase ) {
if ( text.indexOf( phrase.toLowerCase() ) > -1 ){
console.log("Found Phrase: '" + phrase.toLowerCase() + "'");
matches_amount++;
}
else {
//console.log("Could not find. Returned: " + text.indexOf( phrase.toLowerCase()));
}
});
//console.log("Found " + matches_amount + " phrases");
return matches_amount;
}
};
return public;
};
function Overlay (document, event_hub) {
var private = {
element: null
};
var public = {
add: function ( warning_message, high_sev, medium_sev) {
var warning_title = "";
var advisory_message = "";
if(high_sev){
warning_title = "spoiler warning detected";
advisory_message = "this page has phrases that specifically warn about game of thrones spoilers";
} else if(medium_sev){
warning_title = "possible spoiler detected";
advisory_message = "this page has spoilery phrases about game of thrones characters";
} else {
warning_title = "mild spoiler warning";
advisory_message = "this page has game of thrones references and may contain a spoiler";
}
private.element = document.createElement( "div" );
private.element.id = "spoilers_blocker_overlay";
private.element.innerHTML =
"<div>"+
"<div id = 'spoiler_blocker_header' >"+warning_title+"</div>"+
"<div id = 'spoiler_blocker_warning_message' >"+warning_message+"</div>"+
"<div id = 'spoilers_advisory_message' id='spoilers_advisory_message'>"+advisory_message+"</div>"+
"<div class = 'spoilers_blocker_overlay_button' id = 'spoilers_blocker_continue_button' >Continue anyway</div>"+
"</div>";
document.body.appendChild( private.element );
lastMutationSearch = new Date(Date.now());
lastMutationSearch = new Date(lastMutationSearch.getTime() + 1000*5);
alertActive = true;
private.element.querySelector("#spoilers_blocker_continue_button").addEventListener( "click", function () {
event_hub.fire( "continue_button_click" );
});
},
hide: function () {
console.log("Hiding Warning");
//Remove Message
$("#spoilers_blocker_overlay").remove();
lastMutationSearch = new Date(Date.now());
lastMutationSearch = new Date(lastMutationSearch.getTime() + 1000*10);
alertActive = false;
}
};
return public;
};
function Controller ( scanner, overlay, event_hub, storage, banned_phrases, instant_spoiler_phrases, character_names, actor_names, spoiler_verbs_after, spoiler_verbs_before, warning_messages ) {
event_hub.add({
"continue_button_click": function () {
overlay.hide();
lastMutationSearch = new Date(Date.now());
lastMutationSearch = new Date(lastMutationSearch.getTime() + 1000*10);
alertActive = false;
},
});
( function constructor () {
storage.local.get( null, function ( items ) {
if(!alertActive){
var general_threshold = 3;
var high_sev = false;
var medium_sev = false;
var low_sev = false;
//First Check for Instant Spoilers
var banned_phrases_amount = 0;
var instant_spoiler_phrases_amount = scanner.get_matches_amount( window.document.body.innerText, instant_spoiler_phrases );
if(!(instant_spoiler_phrases_amount >= 1)){
//Build Potential Spoiler Array
var potential_spoiler_phrases = [];
character_names.forEach( function ( name ) {
spoiler_verbs_before.forEach( function ( verb ) {
potential_spoiler_phrases.push(verb + name);
});
spoiler_verbs_after.forEach( function ( verb ) {
potential_spoiler_phrases.push(name + verb);
});
});
//console.log("Spoiler Warnings Not Detected. Searching For "+potential_spoiler_phrases.length+" spoiler phrases");
//Search for Full CharacterName + Spoiler Verb / Character First Name + Spoiler spoiler_verbs_before
instant_spoiler_phrases_amount = scanner.get_matches_amount( window.document.body.innerText, potential_spoiler_phrases );
if (!(instant_spoiler_phrases_amount > 0)){
//console.log("Potential Spoilers Not Detected. Searching for General Content");
banned_phrases_amount = scanner.get_matches_amount( window.document.body.innerText, banned_phrases );
if (!(banned_phrases_amount > general_threshold)){
//console.log("General Search found " + banned_phrases_amount + ". Continuing...");
banned_phrases_amount = banned_phrases_amount + scanner.get_matches_amount( window.document.body.innerText, character_names );
if (!(banned_phrases_amount > general_threshold)){
//console.log("General Search + Character Search found " + banned_phrases_amount + ". Finally Searching for Actor Names...");
banned_phrases_amount = banned_phrases_amount + scanner.get_matches_amount( window.document.body.innerText, actor_names );
}
}
} else {
medium_sev = true;
//console.log("Possible Spoiler Detected. Not Searching Any More");
}
} else {
high_sev = true;
//console.log("Instant Spoiler Detected. Not Searching Any Further.");
}
if (banned_phrases_amount >= general_threshold || ( instant_spoiler_phrases_amount >= 1)) {
if ( items.enabled || items.enabled === undefined ) {
if(!alertActive){
console.log("Painting Warning Message");
overlay.add( warning_messages[ Math.floor( Math.random() * warning_messages.length ) ], high_sev, medium_sev );
} else {
console.log("Warning is already active. Not Painting Again");
}
}
} else {
console.log("Failed to Find Game of Thrones Spoilers");
}
} else {
console.log("Alert is already active. Not Searching");
}
});
} () )
};
( function constructor () {
var event_hub = new EventHub();
var warning_messages = [
"This page is Dark and full of Spoilers",
"What do we say to the Page of Spoilers? Not Today!",
"The man who passes the Spoiler should swing the sword.",
"When you play the Game of Spoilers, you win or you die.",
"When Spoilers and worse come hunting... you think it matters who sits on the Iron Throne?",
"There is a beast in every man and it stirs when you put a Spoiler in his Head.",
"Hodor",
"Spoilers cut deeper than swords",
"If they want to give you a Spoiler, take it, make it your own. Then they can’t hurt you with it anymore.",
"Of all the ways I’d kill you, Spoilers would be the last.",
"They say all sorts of crazy Spoilers North of the Wall",
"Spoilers cannot kill a dragon"
];
var spoiler_phrases = [
"game of thrones",
"game-of-thrones",
"game of thrones season eight",
"game of thrones season 8",
"the winds of winter",
"westeros",
"iron throne",
"seven kingdoms",
"dragon",
"dragonglass",
"whitewalker",
"winterfell",
"winter is coming",
"winter is here",
"dothraki",
"asshai",
"bear island",
"beyond the wall",
"black cells",
"blackhaven",
"blackwater bay",
"blackwater rush",
"braavos",
"castamere",
"casterly rock",
"castle black",
"castle stokeworth",
"the citadel",
"the crag",
"craster's keep",
"the crownlands",
"deepwood motte",
"dorne",
"dothraki sea",
"dragonpit",
"dragonstone",
"eastwatch",
"the eyrie",
"the fingers",
"fist of the first men",
"flea bottom",
"free cities",
"frostfangs",
"qarth",
"the gift",
"gods eye",
"great pyramid",
"sept of baelor",
"hall of faces",
"high heart",
"highgarden",
"hornwood",
"house of black and white",
"house of the undying",
"iron islands",
"karhold",
"king's landing",
"kingsroad",
"kingswood",
"lands of always winter",
"lannisport",
"last hearth",
"last river",
"lys",
"moat cailin",
"mole's town",
"mud gate",
"myr",
"naath",
"the neck",
"new ghis",
"the nightfort",
"the north",
"norvos",
"oldtown",
"pentos",
"pyke",
"raventree hall",
"the reach",
"red harbor",
"the redfort",
"rhoyne",
"the riverlands",
"riverrun",
"the shadow tower",
"skagos",
"slaver's bay",
"storm's end",
"the stormlands",
"storrold's point",
"tarth",
"temple of the dosh khaleen",
"tower of joy",
"tower of the hand",
"tyrosh",
"vaes dothrak",
"the vale of arryn",
"valyria",
"volantis",
"volon therys",
"vulture's roost",
"the wall",
"the westerlands",
"whispering wood",
"white harbor",
"blackfyre",
"brightroar",
"dark sister",
"forrester greatsword",
"hearteater",
"heartsbane",
"lady forlorn",
"lightbringer",
"lion's tooth",
"longclaw",
"oathkeeper",
"widow's wail",
"needle",
"faceless"
];
var instant_spoiler_phrases = [
"potential spoilers",
"game of thrones spoiler",
"game-of-thrones-spoiler",
"game_of_thrones_spoiler",
"game of thrones spoilers",
"game-of-thrones-spoilers",
"game_of_thrones_spoilers",
"game of thrones season 8 spoiler",
"spoilers for game of thrones",
"game of thrones finale",
"spoilers are coming",
"jon snow spoilers",
"spoiler alert",
"spoilers alert",
"spoiler ahead",
"spoilers ahead",
"#spoiler",
"season 8 spoiler",
"season 8 game of thrones",
"GoT season 8",
"got spoiler",
"spoilers for game of thrones"
];
var character_names = [
"eddard stark",
"ned stark",
"robert baratheon",
"jaime lannister",
"jaime",
"catelyn stark",
"cersei lannister",
"cersei",
"daenerys targaryen",
"daenerys",
"dany targaryen",
"dany",
"khaleesi",
"rhaegar targaryen",
"rhaegar",
"lyanna stark",
"lyanna",
"jorah mormont",
"jorah",
"petyr baelish",
"littlefinger",
"viserys",
"jon snow",
"jon",
"aegon targaryen",
"aegon",
"sansa stark",
"sansa",
"arya stark",
"arya",
"robb stark",
"theon greyjoy",
"theon",
"reek",
"bran stark",
"bran",
"brandon stark",
"sandor clegane",
"the hound",
"tyrion lannister",
"tyrion",
"khal drogo",
"tywin lannister",
"davos seaworth",
"davos",
"samwell tarly",
"sam tarly",
"samwell",
"margaery tyrell",
"stannis baratheon",
"melisandre",
"jeor mormont",
"bronn",
"varys",
"ygritte",
"gendry",
"tormund giantsbane",
"tormund",
"gilly",
"brienne of tarth",
"brienne",
"ellaria sand",
"daario naharis",
"missandei",
"jaqen h'ghar",
"roose bolton",
"the high sparrow",
"hodor",
"ser gregor",
"gregor clegane",
"the mountain",
"janos slynt",
"irri",
"doreah",
"kevan lannister",
"kevan",
"maester aemon",
"aemon",
"hot pie",
"beric dondarrion",
"beric",
"podrick payne",
"podrick",
"eddison tollett",
"yara greyjoy",
"yara",
"grey worm",
"qyburn",
"meera reed",
"meera",
"jojen reed",
"thoros of myr",
"mace tyrell",
"bowen marsh",
"bowen",
"night king",
"drogon",
"rhaegal",
"viserion",
"ghost",
"nymeria",
"three eyed",
"euron greyjoy",
"euron",
"mother of dragons",
"king in the north",
"yohn royce",
"dragon",
"whitewalker",
"whitewalkers"
];
var actor_names = [
"sean bean",
"mark addy",
"nikolaj coster-waldau",
"michelle fairley",
"lena headey",
"emilia clarke",
"iain glen",
"aidan gillen",
"harry lloyd",
"kit harington",
"sophie turner",
"maisie williams",
"richard madden",
"alfie allen",
"isaac hempstead wright",
"jack gleeson",
"rory mccann",
"peter dinklage",
"jason momoa",
"charles dance",
"liam cunningham",
"john bradley",
"natalie dormer",
"stephen dillane",
"carice van houten",
"james cosmo",
"jerome flynn",
"conleth hill",
"sibel kekilli",
"rose leslie",
"oona chaplin",
"joe dempsie",
"kristofer hivju",
"hannah murray",
"gwendoline christie",
"iwan rheon",
"indira varma",
"michiel huisman",
"nathalie emmanue",
"tom wlaschiha",
"dean-charles chapman",
"michael mcelhatton",
"jonathan pryce",
"julian glover",
"ian beattie",
"kristian nairn",
"mark stanley",
"natalia tena",
"art parkinson",
"esmé bianco",
"hafþór júlíus björnsson",
"dominic carter",
"eugene simon",
"nell tiger free",
"ron donachie",
"donald sumpter",
"amrita acharia",
"roxanne mckee",
"ian gelder",
"ian mcelhinney",
"luke barnes",
"peter vaughan",
"josef altin",
"owen teale",
"brian fortune",
"finn jones",
"ben hawkey",
"richard dormer",
"daniel portman",
"ben crompton",
"gemma whelan",
"tara fitzgerald",
"william & james wilson",
"jacob anderson",
"anton lesser",
"diana rigg",
"kerry ingram",
"ellie kendrick",
"thomas brodie-sangster",
"paul kaye",
"rupert vansittart",
"brenock o'connor",
"roger ashton-griffiths",
"faye marsay",
"michael condron",
"richard brake",
"ian whyte"
]
var spoiler_verbs_after = [
" kill",
" die",
" marry",
" married",
" murder",
" is dead",
" has died",
" was killed",
" return",
" is back",
" betray",
" capture",
" abandon",
" pregnant",
"'s child",
" ambused",
" attack"
];
var spoiler_verbs_before = [
"killed ",
"killed by ",
"married ",
"murdered ",
"stabbed ",
"kills ",
"betrays ",
"betrayed ",
"betrayed by ",
"captured ",
"abandoned ",
"attacks ",
"attacked "
];
new Controller(
new Scanner(),
new Overlay( document, event_hub ),
event_hub,
chrome.storage,
spoiler_phrases,
instant_spoiler_phrases,
character_names,
actor_names,
spoiler_verbs_after,
spoiler_verbs_before,
warning_messages
)
$(document).ready(function(){
//Doc is Ready
//console.log("Document Ready Run...");
new Controller(
new Scanner(),
new Overlay( document, event_hub ),
event_hub,
chrome.storage,
spoiler_phrases,
instant_spoiler_phrases,
character_names,
actor_names,
spoiler_verbs_after,
spoiler_verbs_before,
warning_messages
)
});
$('body').change(function(){
//console.log("Body Element has Changed. Searching Again...");
new Controller(
new Scanner(),
new Overlay( document, event_hub ),
event_hub,
chrome.storage,
spoiler_phrases,
instant_spoiler_phrases,
character_names,
actor_names,
spoiler_verbs_after,
spoiler_verbs_before,
warning_messages
)
});
//Create a Mutation Observer to ReSearch every time something in the page updates
// select the target node
var target = document.querySelector('body');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log("Mutation Detected: " + mutation.type);
if(alertActive){
//console.log("Not Searching. Alert Active");
} else {
var time = new Date(Date.now());
var sinceLastSearch = time.getTime() - lastMutationSearch.getTime();
//console.log("time since last sucessful search: " + sinceLastSearch);
if(sinceLastSearch <= 7*1000){
//console.log("Not Searching. Found Spoilers to Recently Ago");
} else {
//console.log("Starting Mutation Search");
new Controller(
new Scanner(),
new Overlay( document, event_hub ),
event_hub,
chrome.storage,
spoiler_phrases,
instant_spoiler_phrases,
character_names,
actor_names,
spoiler_verbs_after,
spoiler_verbs_before,
warning_messages
)
}
}
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
} () )
} () )