Created
May 16, 2010 18:04
-
-
Save os0x/403049 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 googlechromereleases.blogspot.com | |
// @description Google Chromeのバージョン表記からダウンロードリンクを作る | |
// @namespace http://ss-o.net/ | |
// @include http://googlechromereleases.blogspot.com/* | |
// @require http://gist.github.com/184276.txt | |
// ==/UserScript== | |
(function () { | |
var TEXT = 'descendant::text()[contains(self::text(),".") and not(ancestor::' + ['a', 'textarea', 'script', 'style', 'head'].join(' or ancestor::') + ')]'; | |
var exp = /\d+\.\d+\.(\d+\.\d+)/; | |
linker(document.body); | |
document.body.addEventListener('DOMNodeInserted', nodeListener, false); | |
function linker(doc) { | |
var nodes = $X(TEXT, doc); | |
if (nodes && nodes.length) { | |
nodes.forEach(function (txt) { | |
if (exp.test(txt.nodeValue)) { | |
var text = txt.nodeValue, | |
index; | |
var parent = txt.parentNode; | |
while (text && (index = text.search(exp)) >= 0) { | |
var _txt = txt.splitText(index); | |
var keyword = _txt.nodeValue.match(exp); | |
var keywordLength = keyword[0].length; | |
var __txt = _txt.splitText(keywordLength); | |
var a = document.createElement('a'); | |
a.href = 'http://dl.google.com/chrome/install/' + keyword[1] + '/chrome_installer.exe'; | |
a.appendChild(_txt); | |
parent.insertBefore(a, __txt); | |
text = __txt.nodeValue; | |
txt = __txt; | |
} | |
} | |
}); | |
} | |
} | |
function nodeListener(evt) { | |
document.body.removeEventListener('DOMNodeInserted', nodeListener, false); | |
setTimeout(function () { | |
linker(document.body); | |
document.body.addEventListener('DOMNodeInserted', nodeListener, false); | |
}, 1000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment