/
MelonHusk.js
81 lines (73 loc) · 2.2 KB
/
MelonHusk.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
// ==UserScript==
// @name melonHusk
// @description This userscript will replace all instances of "Elon Musk" and "Elon Reeve Musk" with a pre-defined anagram in web pages loaded by Firefox.
// @match *://*/*
// @version 0.3
// @author geeknik
// @grant none
// ==/UserScript==
(function() {
const replaceRegex = /(Elon Reeve Musk|Elon Musk)/gi;
const anagramsElonMusk = [
"Lemon Kus",
"Monk Lues",
"Sulk Mone",
"Some Knull",
"Lumen Sok",
"Solemn UK",
"Sunk Mole",
"Mules Kon",
"Klue Mons",
"Soul Menk",
"Lone Skum",
"Keno Slum",
"Mule Noks",
"Sunk Mole",
"Lose Munk"
];
const anagramsElonReeveMusk = [
"Universe Mole K",
"Eleven Smoke Ru",
"Revokes Menu El",
"Venue Elk Mores",
"Keen Slum Rover",
"Sneer Vole Muk",
"Revoke Lens Ume",
"Levers Muen Ok",
"Kevens Rule Mo",
"Serve Mule Nok",
"Sleek Oven Rum",
"Reek Lumen Sov",
"Levee Rusk Mon",
"Evoke Lens Rum",
"Serve Lumen Ok"
];
function getRandomAnagram(match) {
let anagramList;
if (match.toLowerCase() === "elon musk") {
anagramList = anagramsElonMusk;
} else if (match.toLowerCase() === "elon reeve musk") {
anagramList = anagramsElonReeveMusk;
}
return anagramList[Math.floor(Math.random() * anagramList.length)];
}
function replaceTextInNode(node) {
let child, next;
switch ( node.nodeType ) {
case 3: // Text node
node.data = node.data.replace(replaceRegex, getRandomAnagram);
break;
case 1: // Element node
case 9: // Document node
case 11: // Document fragment node
child = node.firstChild;
while ( child ) {
next = child.nextSibling;
replaceTextInNode(child);
child = next;
}
break;
}
}
replaceTextInNode(document.body);
})();