Greasemokeyが.user.jsで終わるページをインストールしようとしてしまう件の回避

するためのGreasemonkey Scriptを書きました。

XPathでhrefが.user.jsで終わるリンクを探し*1、その全てに#をつけてインストールダイアログが出るのを回避し、リンクの前にインストール用の新しいリンクを追加します。割と強引にリンクをつっこむので、見た目が崩れる可能性はあります。

accessible user.js for Greasemonkey

// ==UserScript==
// @name           accessible user.js
// @namespace      http://ss-o.net/
// @include        http://*
// @include        https://*
// @require        http://gist.github.com/3242.txt
// ==/UserScript==
$X('//a[substring(@href, string-length(@href) - string-length(".user.js") + 1) = ".user.js"]')
.forEach(function(a){
	var href = a.href;
	a.setAttribute("href", href + "#" );
	var gmlink = document.createElement("a");
	gmlink.href = href;
	gmlink.title = "Install Greasemonkey Script";
	gmlink.textContent = "[G]";
	a.parentNode.insertBefore(gmlink, a);
});

*1:XPathだとend-withとかないから複雑になる。querySelectorでE[foo$="bar"]したい感じ。http://piro.sakura.ne.jp/latest/blosxom/mozilla/xul/2007-09-13_selector-to-xpath.htm