-
-
Save syoichi/933718 to your computer and use it in GitHub Desktop.
Firefox 4.0上のGreasemonkey 0.9.2、Scriptish 0.1において、AutoPagerize(拡張版0.7.2、User Script版0.0.58)で継ぎ足されたページで動作していなかったので修正した。また、Chrome 10.0.648.205上のAutoPagerize 0.2.9、AutoPatchWork 1.8.1でも動作するようにした。 ref. gist.github.com/838690
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== | |
var d = document, | |
b = d.body, | |
range = d.createRange(), | |
regexp = /^\/post\/(\d+)/; | |
function addEditLink(target) { | |
var a = (target.target || target).querySelectorAll('a[class="permalink"]'), | |
l = a.length; | |
while (l) { | |
a[--l].parentNode.insertBefore(range.createContextualFragment('<a href="/edit/' + regexp.exec(a[l].pathname)[1] + '?redirect_to=' + encodeURIComponent(a[l].href) + '">Edit</a>'), a[l].nextSibling); | |
} | |
} | |
range.selectNodeContents(b); | |
d.head.appendChild(range.createContextualFragment('<style type="text/css">a[class="permalink"] + a[href^="/edit/"] { margin: 5px !important; font-size: 10px !important; }</style>')); | |
addEditLink(b); | |
b.addEventListener('AutoPagerize_DOMNodeInserted', addEditLink, false); | |
b.addEventListener('AutoPatchWork.DOMNodeInserted', addEditLink, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment