@require, @resource of Greasemonkey
そういや Greasemonkey 0.8 だと @require の他にもう一つ何か使えたよなと思って試してみた。とりあえず http://labs.gmo.jp/blog/ku/2007/11/firefox3greasemonkeyimport_require.html の hit 数自体が少ないのであまり使われてないのかもしれない ) 。
で、使い方とかは普通に上記に書いてあるんだけど、以下のような感じで。場所指定は Greasemonkey script が置いてある位置を基点として相対 path 指定も受けつけるみたいなので同じ directory や css/, image/ directory なんかを掘ってそこに置いておくと取り扱いが楽。っていうか local で test しながら書くときは必然的にこっちになっちゃうよね。
// ==UserScript== // @name exsample // @namespace http://example.com/userscript/ // @description "@resource" example // @include * // @resource CSS example.css // @resource PNG example.png // ==/UserScript== (function () { GM_addStyle(GM_getResourceText('CSS')); document.getElementsByTagName('img')[0].src = GM_getResourceURL(PNG); } )();
今気付いたけど上記の問答無用で GM_addStyle
する方法は Stylish 入れてなければオレオレ style の適用を toggle できるお手軽な方法かもしれない。 add-on ひとつぶん軽くできるとか highlight や補完の効く editor で編集できるという気楽さとかがメリット、かな ?