Created
April 3, 2010 13:50
-
-
Save 0mg/354494 to your computer and use it in GitHub Desktop.
ttp linker
This file contains hidden or 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== | |
| // @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