Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created September 4, 2009 00:57
Show Gist options
  • Save Constellation/180655 to your computer and use it in GitHub Desktop.
Save Constellation/180655 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name visiable censored+
// @namespace http://gigi-net.net
// @include http://favotter.matope.com/*
// @require http://gist.github.com/3242.txt
// @require http://gist.github.com/105908.txt
// original http://gigi-net.net
// using
// simple version of $X (c)id:os0x
// HTMLStringToDOM (c) id:snaka, id:os0x
// thanks
// ==/UserScript==
(function(){
const clickable = true;
function $A(arr){
return Array.slice.call(arr);
}
//function escapeRegExpString(str){
// return str.replace(/\W/g, '\\$&')
//}
// http://gist.github.com/164430
function HTMLStringToDOM(str){
var html = String(str).replace(/<script(?:[ \t\r\n][^>]*)?>[\S\s]*?<\/script[ \t\r\n]*>|<\/?(?:i?frame|html|script|object)(?:[ \t\r\n][^<>]*)?>/gi, ' ');
var htmlDoc = document.implementation.createHTMLDocument ?
document.implementation.createHTMLDocument('HTMLParser') :
document.implementation.createDocument(null, 'html', null);
var range = document.createRange();
range.selectNodeContents(document.documentElement);
htmlDoc.documentElement.appendChild(htmlDoc.importNode(range.createContextualFragment(html),true));
return htmlDoc;
}
function replaceCensored(nodes){
nodes.forEach(function(node){
$X('descendant-or-self::div[contains(concat(" ",normalize-space(@class)," ")," hentry ") and descendant::span[contains(concat(" ",normalize-space(@class)," ")," censored ")]]', node).map(function(div){
var flag = false;
if(clickable){
div.addEventListener('click', function(){
div.removeEventListener('click', arguments.callee, false);
if(result){
process();
} else {
flag = true;
}
}, false);
}
var href = $X('descendant::div[contains(concat(" ",normalize-space(@class)," ")," info ")]/descendant::a/@href', div)[0].value + '/' + div.getAttribute('id').replace('_', '/');
var result = null;
var p = div.getElementsByClassName('description')[0];
// var censored = $A(p.childNodes).reduce(function(memo, node){
// if(node.className != 'censored') memo.push(node.textContent);
// else memo.push('CENEC');
// return memo;
// }, []).join('').split('');
// var original = null;
var opt = {
method: 'GET',
div : div,
url : href,
onload : function(res){
var dom = HTMLStringToDOM(res.responseText);
result = $X('descendant::span[contains(concat(" ",normalize-space(@class)," ")," entry-content ")]', dom).map(function(node){ return node.textContent }).join("");
// original = result.split('');
// var d = new Diff(censored, original);
// d.a.slice(1);
// d.b.slice(1);
// GM_log(d.lcs.slice(1).map(function(n){
// if(n > 0){
// return(': + : '+d.b.shift());
// } else if(n < 0){
// return(': - : '+d.a.shift());
// } else {
// return(': : '+d.a.shift()+' '+d.b.shift());
// }
// }).join('\n'));
if(flag || !clickable) process();
}
};
function process(){
$A(p.childNodes).forEach(function(node){
p.removeChild(node);
});
p.appendChild(document.createTextNode(result));
}
GM_xmlhttpRequest(opt);
});
});
}
function registerAutoPagerize(){
window.AutoPagerize.addFilter(replaceCensored);
}
if(window.AutoPagerize){
registerAutoPagerize();
} else {
window.addEventListener('GM_AutoPagerizeLoaded', registerAutoPagerize, false);
}
replaceCensored([document]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment