Skip to content

Instantly share code, notes, and snippets.

@taizooo
Created March 3, 2010 05:06
Show Gist options
  • Save taizooo/320343 to your computer and use it in GitHub Desktop.
Save taizooo/320343 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name tabesugi.net path fix
// @namespace http://d.hatena.ne.jp/taizooo/
// @include http://tabesugi.net/memo/*
// ==/UserScript==
var f = function(doc, url, info){
$X('//a[starts-with(@href,"#")]',doc).forEach(function(a){
var hs = a.hash
a.href = url
a.hash = hs
a.target='_blank'
})
}
var addFilterHandler = function(){
window.AutoPagerize.addDocumentFilter(f)
}
//f(document, location.href, '')
if ( window.AutoPagerize && window.AutoPagerize.addDocumentFilter){
addFilterHandler()
}
else
window.addEventListener('GM_AutoPagerizeLoaded', addFilterHandler, false)
// https://gist.github.com/3242
// simple version of $X
// $X(exp);
// $X(exp, context);
// @source https:/raw.github.com/gist/3242
function $X (exp, context) {
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment