|
// mostly via https://gist.github.com/2170045 but also support nodes |
|
function htmlreplace(a, b, element) { |
|
if (!element) element = document.body; |
|
var nodes = element.childNodes; |
|
for (var n=0; n<nodes.length; n++) { |
|
if (nodes[n].nodeType == 3) { |
|
var r = (a instanceof RegExp) ? a : new RegExp(a, 'gi'); |
|
if (nodes[n].textContent) { |
|
nodes[n].nodeValue = nodes[n].textContent.replace(r, b); |
|
} else { |
|
nodes[n].nodeValue = nodes[n].nodeValue.replace(r,b); |
|
} |
|
} else { |
|
htmlreplace(a, b, nodes[n]); |
|
} |
|
} |
|
} |
|
|
|
replacements = [ |
|
['candy bar', 'chocolate gobblernaught'], |
|
['car', 'motorized rollingham'], |
|
['firework', 'merry fizzbang'], |
|
['pc', 'wunderbahboxes'], |
|
['milk', 'cow juice',], |
|
['gravy', 'meat water',], |
|
['power cable', 'electrorope'], |
|
['burger', 'beef wellington ensemble with lettuce'], |
|
['pen', 'whimsy flimsy mark and scribbler'], |
|
[/\bdoor ?knobs?\b/, 'twisting plankhandle'], |
|
['sandwich', 'breaddystack'], |
|
['keyboard', 'hoighty toighty tippy typers'], |
|
['escalator', 'upsy stairsy'], |
|
['sweater', 'knittedy wittedy sheepity sleepity'], |
|
['cookie', 'choco chip bucky wicky'], |
|
['sex', 'peepee friction pleasure'], |
|
['screwdriver', 'pip pip gollywock'], |
|
['gun', 'rooty tooty point-n-shooty'], |
|
[/\blight ?bulbs?\b/, 'ceiling-bright'], |
|
['ball', 'blimpy bounce'], |
|
['snake', 'slippery dippy long mover'], |
|
['road', 'cobble-stone-clippity-clop'], |
|
]; |
|
|
|
for (var i=0; i<replacements.length; i++) { |
|
console.log(replacements[i]); |
|
htmlreplace(replacements[i][0], replacements[i][1]); |
|
} |