Skip to content

Instantly share code, notes, and snippets.

@azu
Created September 3, 2009 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/180072 to your computer and use it in GitHub Desktop.
Save azu/180072 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name censored
// @namespace http://efcl.info/
// @include http://favotter.matope.com/*
// ==/UserScript==
var _doc = document;
var replaceLists = {
"<censored>" : "お母さん",
"<censored>" : "お母さん",
}
var init = function (doc){
var txt = xpath(doc , 'descendant::text()[string-length(normalize-space(self::text())) > 0 and not(ancestor::textarea) and not(ancestor::script) and not(ancestor::style)]');
for(var i=0,tl=txt.snapshotLength; i<tl; ++i){
var df,item = txt.snapshotItem(i),
text = item.nodeValue.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'),
parent = item.parentNode, range = document.createRange();
for (var j in replaceLists){
text = text.replace(j,function(p){
return replaceLists[j];
});
}
var newText = text;
range.selectNode(item);
df = range.createContextualFragment(newText);
parent.replaceChild(df, item);
range.detach();
}
}
init(_doc);
function xpath(context, query){
return _doc.evaluate(
query, context, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
)
}
if(window.AutoPagerize) {
addFilterHandler();
}else{
window.addEventListener('GM_AutoPagerizeLoaded',boot,false);
}
function addFilterHandler(){
window.AutoPagerize.addFilter(function(docs){
docs.forEach(init);
});
}
function e(id) {
return _doc.getElementById(id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment