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
|
var map = {};
var maps = [ start, end, complete, anywhere ];
for (var i = 0; i < maps.length; i++) {
for (attr in maps[i]) {
map[attr] = maps[i][attr];
}
}
var concatString = function(obj) {
var parts = [];
for (key in obj) {
parts.push(key);
}
return parts.join('|');
};
var regex = '^(' + concatString(start) + ')|(' + concatString(end) + ')$|(' + concatString(anywhere) + ')|( ' + concatString(complete) + ' )';
var searchFor = new RegExp(regex, 'i');
function capitalize(word) {
var first = word.charAt(0);
var rest = word.slice(1);
return first.toUpperCase() + rest.toLowerCase();
}
function matchCase(old_word, replacement) {
if (replacement.toLowerCase() == old_word.toLowerCase()) return old_word;
var first = old_word.charAt(0);
var second = old_word.charAt(1);
if (/[a-z]/.test(first)) return replacement.toLowerCase();
if (/[A-Z]/.test(second)) return replacement.toUpperCase();
return capitalize(replacement);
}
function findMatch(word) {
return map[word];
}
function swapWord(word) {
return matchCase(word, word.toLowerCase().replace(searchFor, findMatch));
}
function genderswap(text) {
return text
.replace(/\b([a-z][\w']+)\b/gi, swapWord)
.replace(/\b(hers?|hi[ms])\b[\.\,\;\:\]\}\)\?]?(\s+\S+)?/gim, function(match) {
if (/hers?/i.test(match)) {
return translateHer(match);
} else {
return translateHim(match);
}
})
.replace(/\b([a-z]+[,;:'".]*)\s+Miss(?= [A-Z][a-z])/g, "$1 Mr.");
}
function translateHim(text) {
return text
.replace(/\bhim\b/g,"her")
.replace(/\bhis(?=[\.\,\;\:\]\}\)\?])/g,"hers")
.replace(/\bhis\b/g,"her")
.replace(/\bHim\b/g,"Her")
.replace(/\bHis(?=[\.\,\;\:])/g,"Hers")
.replace(/\bHis\b/g,"Her")
;
}
function translateHer(text) {
return text
.replace(/\bher\b(?=[\.\,\;\:\]\}\)\?])/g, 'him')
.replace(/\bher\sher\b/g, "him his")
.replace(/\bher\b(?=\s(?=a\b|an\b|the\b|some\b|any\b|0|1|2|3|4|5|6|7|8|9|one|two|three|thirt|four|five|fift|six|seven|eight|nine|ten|eleven|twelve|twenty))/g, "him")
.replace(/\bher\b(?=\s(?=aboard|about|above|across|after|against|along|amid|among|around|as|at|before|behind|below|beneath|beside|besides|between|beyond|but\b|by\b|concerning|considering|despite|down|during|except|excepting|excluding|following|for|from|in\b|inside|into|like|minus|of\b|off\b|often|on\b|onto|opposite|outside|over|past|per\b|plus|regarding|since\b|than\b|through|to\b|toward|towards|under\b|underneath|unlike|until|up\b|upon|versus|via\b|with\b|within|without|not|and\b|feel\b))/g,"him")
.replace(/\bit\sher\sall\b/g,"it his all")
.replace(/\bher\sall\b/g,"him all")
.replace(/\bher\b/g,"his")
.replace(/\bhers\b/g,"his")
.replace(/\bHer\b(?=[\.\,\;\:\]\}\)\?])/g,"Him")
.replace(/\bHer\sher\b/g,"Him His")
.replace(/\bHer\b(?=\s(?=a\b|an\b|the\b|some\b|any\b|many\b|0|1|2|3|4|5|6|7|8|9|one|two|three|thirt|four|five|fift|six|seven|eight|nine|ten|eleven|twelve|twenty))/g, "Him")
.replace(/\bHer\b(?=\s(?=aboard|about|above|across|after|against|along|amid|among|around|as|at|before|behind|below|beneath|beside|besides|between|beyond|but\b|by\b|concerning|considering|despite|down|during|except|excepting|excluding|following|for|from|in\b|inside|into|like|minus|of\b|off\b|often|on\b|onto|opposite|outside|over|past|per\b|plus|regarding|since\b|than\b|through|to\b|toward|towards|under\b|underneath|unlike|until|up\b|upon|versus|via\b|with\b|within|without|not|and\b|feel\b))/g,"Him")
.replace(/\bit\sHer\sall\b/g,"it His all")
.replace(/\bHer\sall\b/g,"Him all")
.replace(/\bHer\b/g,"His")
.replace(/\bHers\b/g,"His");
}
function jailbreak(node){
var treeWalker = document.createTreeWalker(
node,
NodeFilter.SHOW_TEXT,
null,
false
);
while(treeWalker.nextNode()) {
var current = treeWalker.currentNode;
current.textContent = genderswap(current.textContent);
}
}
chrome.runtime.sendMessage({name: "isPaused?"}, function(response) {
if (response.value != 'true') {
jailbreak(document.body);
document.body.addEventListener('DOMNodeInserted', function(event) {
jailbreak(event.target);
});
}
}); |
Partager