Created
December 15, 2016 06:56
-
-
Save roytam1/51fddab5f3c00ae2cde70ae841b2267f to your computer and use it in GitHub Desktop.
big5-replace bookmarklet
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
javascript:void%20function(){function%20u(e,C,t){t||(t=document.body);for(var%20a=t.childNodes,o=new%20RegExp(e,%22gi%22),n=0;n%3Ca.length;n++)3==a[n].nodeType%3Fa[n].nodeValue=a[n].nodeValue.replace(o,C):%22textarea%22==(x=a[n].tagName.toLowerCase())||%22input%22==x%26%26%22text%22==a[n].getAttribute(%22type%22)%3Fa[n].value=a[n].value.replace(o,C):u(e,C,a[n])}function%20e(t){try{for(var%20a=0;a%3CC.length;a++)u(C[a][0],C[a][1],t.document.body);for(var%20o=0;o%3Ct.frames.length;o++)e(t.frames[o])}catch(n){}}var%20C=[[%22%5Cu7DAB%22,%22%5Cu7DDA%22],[%22%5Cu7D89%22,%22%5Cu7E61%22],[%22%5Cu92B9%22,%22%5Cu93FD%22],[%22%5Cu6ED9%22,%22%5Cu532F%22],[%22%5Cu6822%22,%22%5Cu67CF%22],[%22%5Cu5CEF%22,%22%5Cu5CF0%22],[%22%5Cu9834%22,%22%5Cu7A4E%22],[%22%5Cu90A8%22,%22%5Cu6751%22],[%22%5Cu7740%22,%22%5Cu8457%22],[%22%5Cu53CC%22,%22%5Cu96D9%22],[%22%5Cu5553%22,%22%5Cu555F%22]];e(window)}(); |
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
/* | |
Maillist Big5 non-registered characters replacer | |
Use http://chriszarate.github.io/bookmarkleter/ to create bookmarklet | |
*/ | |
var tcsc = [ | |
["綫", "線"], | |
["綉", "繡"], | |
["銹", "鏽"], | |
["滙", "匯"], | |
["栢", "柏"], | |
["峯", "峰"], | |
["頴", "穎"], | |
["邨", "村"], | |
["着", "著"], | |
["双", "雙"], | |
["啓", "啟"] | |
]; | |
function htmlreplace(a, b, element) { | |
if (!element) element = document.body; | |
var nodes = element.childNodes; | |
var r = new RegExp(a, 'gi'); | |
for (var n=0; n<nodes.length; n++) { | |
if (nodes[n].nodeType == 3) { //Node.TEXT_NODE == 3 | |
nodes[n].nodeValue = nodes[n].nodeValue.replace(r, b); | |
} else if ((x = nodes[n].tagName.toLowerCase()) == "textarea" || (x == "input" && nodes[n].getAttribute("type") == "text")) { | |
nodes[n].value = nodes[n].value.replace(r, b); | |
} else { | |
htmlreplace(a, b, nodes[n]); | |
} | |
} | |
} | |
function traverse(w){ | |
try{ | |
/* Manipulate w.document */ | |
for(var j=0; j<tcsc.length; j++) {htmlreplace(tcsc[j][0],tcsc[j][1],w.document.body);} | |
for(var i=0; i<w.frames.length; i++) | |
traverse(w.frames[i]); | |
} | |
catch(e){ | |
/* Do something with e or just do nothing */ | |
} | |
} | |
traverse(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment