Greasemonkeyの習作
会社の昼休みにアク禁されたサイトを眺めるため、そのURLをThe Coral Content Distribution Network(いわゆるCoralプロキシ)のURLに書き換えるブックマークを拵えたが、今回はそれをGreasemonkeyでやってみた。
初のGreasemonkeyの臭作。
// ==UserScript==
// @name Coral proxy Userscript
// @namespace http://mhiro-jp.hp.infoseek.co.jp/
// @description Enforce change URL to Coral proxy URL
// @include *
// @exclude http://localhost*
// @exclude http://127.0.0.1*
// ==/UserScript==
(function () {
var URLList = new Array();
URLList[0] = 'bbspink.com';
URLList[1] = 'aria2.sourceforge.net';
// URLList[2] = 'アク禁されているドメイン名を1行ずつ追加していく';
var re1 = new RegExp('^[^\/]+\/{2,3}[^\/]*(' + URLList.join('|').replace(/\./g, '\.') + ')\/', 'i');
var re2 = new RegExp('^([^\/]+)\/{2,3}([^\/]*)(' + URLList.join('|').replace(/\./g, '\.') + ')\/', 'i');
if (document.location.href.match(re1)) {
document.location.href = document.location.href.replace(/^([^\/]+)\/{2,3}([^\/]+)\//i,'$1//$2.nyud.net/');
} else {
for (i=0;i<document.links.length;i++) {
if (!document.links[i].href.match(/^[^\/]+\/{2,3}[^\/]+\.nyud.net\//i)) {
document.links[i].href = document.links[i].href.replace(re2, '$1//$2$3.nyud.net/');
}
}
}
})();
こっちのほうが簡単だが、Greasemonkeyは場合によってはSeaMonkeyの描画を遅くするから嫌い。
ちなみに、SeaMonkey用Greasemonkey 0.8.6でしか検証していない。
Comments