Skip to content

Instantly share code, notes, and snippets.

@0mg
Created April 3, 2010 13:50
Show Gist options
  • Select an option

  • Save 0mg/354494 to your computer and use it in GitHub Desktop.

Select an option

Save 0mg/354494 to your computer and use it in GitHub Desktop.
ttp linker
// ==UserScript==
// @include *
// ==/UserScript==
/* このスクリプトは Opera 10.10 をクラッシュさせるので使用禁止 */
window.addEventListener("DOMContentLoaded", function() {
var texts = document.
evaluate(".//text()[contains(self::text(),'ttp') and not(ancestor::a) and not(ancestor::textarea) and not(ancestor::script)]",
document.body, null, 7, null);
for (var i = 0; i < texts.snapshotLength; i++) {
var ttp = texts.snapshotItem(i).nodeValue.
replace(/(h?(ttps?:[/][/]\S+))/g,
'<a href="h$2">$1</a>');
var range = document.createRange();
range.selectNodeContents(document.body);
var a = range.createContextualFragment(ttp);
texts.snapshotItem(i).parentNode.
replaceChild(a, texts.snapshotItem(i));
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment