PDFをGoogle Docsで開くグリモンをAutoPagerize対応に

PDFファイルをAdobe Readerで開かずに、Googleドキュメントのviewerで開く
Kooniesさんのあの素晴らしいスクリプトを、AutoPagerizeに対応させてみました。
ついでにhttpsにも対応。
オリジナル:快適!PDFのリンクをGoogle docs Viewer経由に置き換えるgreasemonkey - Koonies/こりゃいいな!

追記

otsuneさんの改良版。はてブを使っている人は特にこっちを推奨。
インストールも簡単です。
PDF/PPT Viewer with Google Docsをqueryselector版に修正した - otsune's SnakeOil - subtech


一応以下を残しておきます。

// ==UserScript==
// @name           PDF/PPT/TIF viewer with Google docs
// @namespace      http://d.hatena.ne.jp/Koonies/
// @include        http://*
// @include        https://*
// @exclude        http://docs.google.com/*
// @version        1.3
// ==/UserScript==

(function() {
    if (location.href.indexOf("http://docs.google.com/") != -1) return;
    function handle(node){
        var items = document.evaluate('.//a',node,null,7,null);
        for (var i = 0; i < items.snapshotLength; i++)
        {
             var item = items.snapshotItem(i);
			if (item.href.match(/^https*:([^?]+|[^:]+)\.(pdf|ppt|tif|tiff)$/i)) {
				var ico = document.createElement("img");
				ico.src = "http://docs.google.com/favicon.ico";
				item.parentNode.insertBefore(ico, item);
				item.href = 'http://docs.google.com/viewer?url=' + item.href;
			}
        }
    }
    document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
        var node = evt.target;
            handle(node);
    }, false);
    handle(document);
})();

userscripts.orgにあげるものでもないので、更新したい方はコピペでお願いしますね。


PDFが2ページ目以降に出てきてもこれでOKです。

onclickで動作する改作バージョンもあるようですが、そちらはVimperatorで動作しなかったため避けました。