Created
November 16, 2015 09:34
-
-
Save ThePengwin/57d495e31937c72204b7 to your computer and use it in GitHub Desktop.
Replace autospurdo code to use cloudtobutt's textnode walker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name autoSpurdo | |
// @description Convert text on every page into spurdo | |
// @namespace installgen2 | |
// @include * | |
// @version 4 | |
// @grant none | |
// ==/UserScript== | |
walk(document.body); | |
function walk(node) | |
{ | |
// I stole this function from here: | |
// http://is.gd/mwZp7E | |
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 | |
spurdoNode(node); | |
break; | |
} | |
} | |
function spurdoNode(node) { | |
var text = node.nodeValue; | |
var replacements = [ | |
['wh', | |
'w'], | |
[ | |
'th', | |
'd' | |
], | |
[ | |
'af', | |
'ab' | |
], | |
[ | |
'ap', | |
'ab' | |
], | |
[ | |
'ca', | |
'ga' | |
], | |
[ | |
'ck', | |
'gg' | |
], | |
[ | |
'co', | |
'go' | |
], | |
[ | |
'ev', | |
'eb' | |
], | |
[ | |
'ex', | |
'egz' | |
], | |
[ | |
'et', | |
'ed' | |
], | |
[ | |
'iv', | |
'ib' | |
], | |
[ | |
'it', | |
'id' | |
], | |
[ | |
'ke', | |
'ge' | |
], | |
[ | |
'nt', | |
'nd' | |
], | |
[ | |
'op', | |
'ob' | |
], | |
[ | |
'ot', | |
'od' | |
], | |
[ | |
'po', | |
'bo' | |
], | |
[ | |
'pe', | |
'be' | |
], | |
[ | |
'pi', | |
'bi' | |
], | |
[ | |
'up', | |
'ub' | |
], | |
[ | |
'va', | |
'ba' | |
], | |
[ | |
'ck', | |
'gg' | |
], | |
[ | |
'cr', | |
'gr' | |
], | |
[ | |
'kn', | |
'gn' | |
], | |
[ | |
'lt', | |
'ld' | |
], | |
[ | |
'mm', | |
'm' | |
], | |
[ | |
'nt', | |
'dn' | |
], | |
[ | |
'pr', | |
'br' | |
], | |
[ | |
'ts', | |
'dz' | |
], | |
[ | |
'tr', | |
'dr' | |
], | |
[ | |
'bs', | |
'bz' | |
], | |
[ | |
'ds', | |
'dz' | |
], | |
[ | |
'es', | |
'es' | |
], | |
[ | |
'fs', | |
'fz' | |
], | |
[ | |
'gs', | |
'gz' | |
], | |
[ | |
' is', | |
' iz' | |
], | |
[ | |
'ls', | |
'lz' | |
], | |
[ | |
'ms', | |
'mz' | |
], | |
[ | |
'ns', | |
'nz' | |
], | |
[ | |
'rs', | |
'rz' | |
], | |
[ | |
'ss', | |
'sz' | |
], | |
[ | |
'ts', | |
'tz' | |
], | |
[ | |
'us', | |
'uz' | |
], | |
[ | |
'ws', | |
'wz' | |
], | |
[ | |
'ys', | |
'yz' | |
], | |
[ | |
'alk', | |
'olk' | |
], | |
[ | |
'ing', | |
'ign' | |
], | |
[ | |
'ic', | |
'ig' | |
], | |
[ | |
'ng', | |
'nk' | |
], | |
[ | |
'kek', | |
'geg' | |
], | |
[ | |
'epic', | |
'ebin' | |
], | |
[ | |
'some', | |
'sum' | |
], | |
[ | |
'meme', | |
'maymay' | |
], | |
]; | |
var ebinFaces = [ | |
':D', | |
':DD', | |
':DDD', | |
':-D', | |
'XD', | |
'XXD', | |
'XDD', | |
'XXDD' | |
]; | |
function getEbinFace() { | |
return ebinFaces[Math.floor(Math.random() * ebinFaces.length)]; | |
} | |
text = text.toLowerCase(); | |
replacements.forEach(function (filter) { | |
var replaceFrom = new RegExp(filter[0], 'gm'), | |
replaceTo = filter[1]; | |
text = text.replace(replaceFrom, replaceTo); | |
}); | |
while (text.match(/\.|,(?=\s|$)/m)) { | |
text = text.replace(/\.|,(?=\s|$)/m, ' ' + getEbinFace()); | |
} | |
// var ebinFaceFound = false; | |
// ebinFaces.forEach(function (face) { | |
// if (text.indexOf(face) != - 1) { | |
// ebinFaceFound = true; | |
// } | |
// }); | |
// if (!ebinFaceFound) { | |
// text += ' ' + getEbinFace(); | |
// } | |
node.nodeValue = text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment