- 2008-03-17 (月) 23:35

これは何?
Twitter の発言で、L:住所 と表示されているロケーション情報に、Google Maps へのリンクを追加する Greasemonkey です。
使い方
下記リンクからインストールしてください。例によって Greasemonkey が必要です。(Safari の場合は GreaseKit)
インストール後、Twitter の L:住所 という部分が Google Maps へのリンクになります。
twittergooglemapslink.user.js (version 1.0)
Userscripts.org で管理することにしました。
Twitter Google Maps Link – Userscripts.org
その他、技術的なこと
既に同じグリモンがあるかもしれませんが、見つからなかったので作りました。
今回、初めて XPath を使いました。最初 DOM でやろうと思ったんですが、処理が煩雑になるし XPath の方が早いらしいので。以下のリンクを参考にしました。
・Introduction to using XPath in JavaScript - MDC
・ JavaScript-XPath をリリースしました!さあ、あなたも XPath を使おう!(解説付き) - IT戦記
// ==UserScript==
// @name Twitter Google Maps Link
// @namespace http://www.sukechan.net/
// @description Location is convert into the link to Google Maps.
// @include http://twitter.com/*
// @version 1.0
// ==/UserScript==
(function() {
var x = document.evaluate('//*[@class="entry-title entry-content"] | //div[@class="desc"]/descendant::p[1]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < x.snapshotLength; i++) {
var idx = x.snapshotItem(i).textContent.indexOf("L:")
if (idx >= 0) {
loc = x.snapshotItem(i).textContent.substr(idx + 2).split(/\s+/)[0].replace(/[\n\r\s]/g, "");
x.snapshotItem(i).innerHTML = x.snapshotItem(i).innerHTML.replace(loc, "" + loc + "");
}
}
})();