Created
May 1, 2009 03:29
-
-
Save taizooo/104854 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name add edit link on tumblr | |
// @namespace http://d.hatena.ne.jp/taizooo/ | |
// @include http://*.tumblr.com/* | |
// @exclude http://www.tumblr.com/* | |
// ==/UserScript== | |
(function(){ | |
function f(doc){ | |
$X('.//a[@class="permalink"]', doc).forEach(function(a){ | |
var match = a.href.match(/\/post\/(\d+)/); | |
var id = match[1]; | |
var ae = document.createElement('a'); | |
var textNode = document.createTextNode('Edit'); | |
ae.appendChild(textNode); | |
ae.href = '/edit/' + id + '?redirect_to=' + encodeURIComponent(a.href); | |
ae.className = 'edi_perm'; | |
ae.style.margin = '5px'; | |
ae.style.fontSize = '10px'; | |
a.parentNode.insertBefore(ae, a.nextSibling); | |
}); | |
} | |
f(document); | |
function addFilter() { | |
window.AutoPagerize.addFilter(function(docs){ | |
for (var i = 0,l = docs.length;i < l;i++) f(docs[i]); | |
}); | |
} | |
if (window.AutoPagerize && window.AutoPagerize.addFilter) | |
addFilter(); | |
else | |
window.addEventListener('GM_AutoPagerizeLoaded', addFilter, false); | |
})() | |
// simple version of $X | |
// $X(exp); | |
// $X(exp, context); | |
// @source http://gist.github.com/3242.txt | |
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