-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Greasemonkey userscript for the same thing
- Loading branch information
boxmein
committed
Dec 29, 2013
1 parent
fe5a8d4
commit 54fa500
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// ==UserScript== | ||
// @name Word To Word Replacer | ||
// @description Replaces words predetermined by a wordlist | ||
// @version 1.0 | ||
// @namespace http://boxmein.x10.mx/ | ||
// @include * | ||
// @run-at document-end | ||
// ==/UserScript== | ||
|
||
// ctrl+f "var replacements" | ||
|
||
// just a mash together of userscript stuff and cloud-to-butt stuff | ||
|
||
// http://wiki.greasespot.net/Content_Script_Injection | ||
function contentEval(source) { | ||
if ('function' == typeof source) { | ||
source = '(' + source + ')();' | ||
} | ||
var script = document.createElement('script'); | ||
script.setAttribute("type", "application/javascript"); | ||
script.textContent = source; | ||
document.body.appendChild(script); | ||
document.body.removeChild(script); | ||
} | ||
|
||
|
||
|
||
contentEval(function() { | ||
|
||
|
||
var replacements = [ | ||
// a list of objects with keys from and to, signifying what to find and what | ||
// to replace the string to | ||
// the from key can also be a Javascript compatible (perl compatible) regex | ||
// {"from": "cloud", "to": "butt" }, | ||
{"from": /[aeiou]/ig, "to": "o"} | ||
// ... | ||
]; | ||
|
||
// I stole this 101% from https://github.com/panicsteve/cloud-to-butt/blob/master/Source/content_script.js | ||
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 | ||
handleText(node); | ||
break; | ||
} | ||
} | ||
|
||
function handleText(textNode) | ||
{ | ||
var v = textNode.nodeValue; | ||
|
||
for (var i=0, r=replacements; i<r.length; i++) { | ||
v = v.replace(r[i].from, r[i].to); | ||
} | ||
|
||
textNode.nodeValue = v; | ||
} | ||
|
||
// notifying any stronger would be disastrously annoying | ||
if (replacements.length == 0) | ||
console.log('Configure replacements in script source code'); | ||
|
||
walk(document.body, handleText); | ||
}); |