横浜市立図書館のWebページを少しだけ快適にする
横浜市立図書館は、Webページで予約できて、市立図書館であればどこでも借りたり返却したりできて便利である。
だが、ちょっとした操作でいちいち「〜しますか?」と確認してきてちょっと鬱陶しい。
というわけでGreasemonkeyのスクリプトを書いてみたので紹介する。
// ==UserScript== // @name Yokohama City Library Autoresponse // @namespace http://d.hatena.ne.jp/kare/ // @description 横浜市立図書館のWebページをちょっとだけ快適にする // @include https://www.lib.city.yokohama.jp/cgi-bin/Sww5sife.sh // @include https://www.lib.city.yokohama.jp/cgi-bin/Sww5slgo.sh // @include https://www.lib.city.yokohama.jp/cgi-bin/Sww5skce.sh // @include https://www.lib.city.yokohama.jp/cgi-bin/Sww5syce.sh // @exclude // ==/UserScript== var textnodes = document.evaluate( "//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i <textnodes.snapshotLength; i++) { var message = textnodes.snapshotItem(i).data; if (message.match('ログアウトしますか?') || message.match('ログインしています。')) { document.forms[0].submit(); break; } else if (message.match('ログインしました。')) { // 本当は execCGI(2) を呼び出したいんだけど... document.forms[0].action = "/cgi-bin/Sww5stop.sh"; document.forms[0].submit(); break; } }
今更ながらGreasemonkeyは、初めて使ったのでその点はご容赦を。
# これが2年ぶりのブログだったりする。。。