日経BPのメールマガジン用Greasemonkey
私は日経BP(nikkei BPnet)のメールマガジンをとっているのだが、このメールマガジンの本文にあるURLには、末尾に「?ml」と入っている。
(参考例)田原総一朗 × 田勢康弘(2)〜検察からアメリカ発 金融危機までを語る
http://www.nikkeibp.co.jp/article/column/20090414/146367/?ml
これはメールマガジンからの来訪者を峻別するために「?ml」と入れているのだろう。アクセス解析でわかるから。
http://www.nikkeibp.co.jp/article/column/20090414/146367/
しかし困るのは、はてなブックマークするときだ。「?ml」が邪魔なのだ。「?ml」あり・なしで、ふたつのブクマに分かれてしまっている。いちいち手動で「?ml」を削ってブクマするのは面倒くさい。本来ならば、メールマガジンからの来訪者を日経BPのWebサイトでリダイレクトして「?ml」を削るべきなのだが、そのような実装になってない。
というわけで自動的に削るようグリモン(Greasemonkeyスクリプト)を書いてみた。グリモンを書くのは生まれて初めてだ。Javascriptとか全然わかんないし。まあ、1行しかないけどな。
// ==UserScript== // @name nikkei BPnet URL change // @namespace http://d.hatena.ne.jp/michinao/ // @description remove "?ml" in URL at nikkei BPnet Website // @include http://*.nikkeibp.co.jp/article/*/?ml // @include http://*.nikkeibp.co.jp/article/*/?set=* // @include http://*.nikkeibp.co.jp/article/*/?ST=yahoo* // @include http://*.nikkeibp.co.jp/article/*/?rt* // @include http://*.nikkeibp.co.jp/article/*/?bv* // @include http://*.nikkeibp.co.jp/article/*/?P=1 // ==/UserScript== location.href = location.href.replace(/\?.*/, '');
これでURL末尾の「?ml」や「?set=relate」「?ST=yahoo_headlines」を削れる。
下は狼のまとめサイト、Witch Hunting Girlscouts用のグリモンを書いた。リンク中の「www.transfer-me」を削除してしまうスクリプト。
// ==UserScript== // @name www.transfer-me remove // @namespace http://michinao.jp/mt/ // @description remove "www.transfer-me" in URL at Witch Hunting Girlscouts. // @include http://www.machineworks.co.uk/whg/* // ==/UserScript== (function () { var xpath_anchor = "//a"; var res = document.evaluate( xpath_anchor, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var i, anchor; for (i = 0; anchor = res.snapshotItem(i); i++) { anchor.href = anchor.href.replace(/^http:\/\/www\.transfer-me\.com\/index\.php\?goto=h?ttp/, 'http'); anchor.href = anchor.href.replace(/^http:\/\/www\.google\.com\/url\?sa=D&q=h?ttp/, 'http'); } })();