Skip to content

Instantly share code, notes, and snippets.

@os0x
Created May 16, 2010 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os0x/403049 to your computer and use it in GitHub Desktop.
Save os0x/403049 to your computer and use it in GitHub Desktop.
// ==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