Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name cleanAutoPager
// @namespace http://d.hatena.ne.jp/
// @description
// @include http://*
// @include https://*
// @exclude https://mail.google.com/*
// ==/UserScript==
(function(){
if(window.top!=window)return;
if (window.AutoPagerizeWedataSiteinfo) {
var SITEINFO = window.AutoPagerizeWedataSiteinfo;
}else{
return;
}
var list = SITEINFO; // no top & bottom SITEINFO yet
var locationHref = location.href;
function $X(exp, context) {
if ($X.forceRelative) {
exp = exp.replace(/id\(\s*(["'])([^"']+)\1\s*\)/g, './/*[@id="$2"]');
exp = exp.indexOf('(//') == 0
? '(.//' + exp.substring(3)
: (exp[0] == '/' ? '.' : './') + exp;
}
context || (context = document);
var expr = (context.ownerDocument || context).createExpression(exp, function (prefix) {
return document.createNSResolver(context.documentElement || context).lookupNamespaceURI(prefix) ||
context.namespaceURI || document.documentElement.namespaceURI || "";
});
var result = expr.evaluate(context, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.STRING_TYPE : return result.stringValue;
case XPathResult.NUMBER_TYPE : return result.numberValue;
case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
// not ensure the order.
var ret = [], i = null;
while (i = result.iterateNext()) ret.push(i);
return ret;
}
return null;
}
var nlist = [];
var clist = [];
list.forEach(function(_item) {
try {
_item = _item.data || _item;
_item.regurl = new RegExp(_item.url);
if (!_item.nextLink || !_item.pageElement) return;
nlist.push(_item);
} catch (e){
opera.postError(e.description,_item);
}
});
nlist.some(function(info) {
try {
if (info.regurl.test(locationHref)) {
if (!info.regurl.test('http://a')){
clist.push(info);
if(!window.apclean)window.apclean = document.documentElement.appendChild((function(s){s.type='text/css';s.id='AP_clean';s.innerHTML='*{display:none}';return s})(document.createElement('style')));
window.addEventListener('DOMContentLoaded',function(){
var re=/AP_\w*_element/;
var CLEAN='AP_clean_element';
var DIRTY='AP_dirty_element';
if(document.getElementsByClassName(CLEAN).length)return;
var elements=$X(info.pageElement);
elements.forEach(function(ele){
if(re.test(ele.className))ele.className=ele.className.replace(re,CLEAN);
else ele.className+=' '+CLEAN;
while(ele!=document.body){
var p=ele.parentNode;
if(p.className.indexOf(CLEAN)>=0)break;
[].forEach.call(p.children,function(e){
if(e==ele){if(e.className.indexOf(DIRTY)>=0)e.className=e.className.replace(re,CLEAN)}
else if(!re.test(e.className))e.className+=' '+DIRTY;
});
ele=p;
}
});
document.getElementById('AP_clean').textContent = '.AP_dirty_element:not([id="autopagerize_icon"]){display:none!important;} .AP_clean_element{width:100%!important;}';
if(window.AutoPagerize){
var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
var pageHeight = window.opera ? document.documentElement.clientHeight : document.body.offsetHeight;
if (window.innerHeight >= pageHeight) {
document.body.appendChild(document.createElementNS(HTML_NAMESPACE, 'div')).setAttribute('style','position:absolute;bottom:-1px;height:1px;width:1px;');
}
}
},false)
window.AutoPagerizeWedataSiteinfo = clist;
return;
}
}
} catch(e) {
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.