アナログ
RSS  

PDFをGoogle docs経由で開くをAutoPagerizeに対応2010/09/26 07:23

AutoPagerizeを使い始めたので、「PDFをGoogle docs経由で開く」をAutoPagerize対応にしました。

と言っても前回パクっ参考にしたソースがAutoPagerize対応だったのをAutoPagerize非対応にして使ってたので、元に戻すというのが正しのですけれど……

なので詳細はPDFをGoogle docs経由で開くquerySelector版を見てくださいと。

このスクリプトは次の画像のようにPDF/PTT/TIFのリンクをGoogle docsで開くように書き換え、元のリンクをアイコンにして表示するものです。

PDFのリンクをGoogle Docsに置き換える
// @name           PDF/PPT/TIF viewer with Google docs
// @namespace      http://puppet.asablo.jp/blog/
// @include        http://*
// @exclude        http://docs.google.com/*
// @exclude        http://*.2ch.net/*
// @version        0.4
// ==/UserScript==
// Based on script by Koonies (http://d.hatena.ne.jp/Koonies/): http://userscripts.org/scripts/show/59557
// Based on script by otsune (http://subtech.g.hatena.ne.jp/otsune/20100124/pdfpptviewerwithgoogle)

(function() {
    function handle(node){
        var l = node.querySelectorAll('a[href$=".pdf"], a[href$=".ppt"], a[href$=".tif"]');
        for (var i = 0; i < l.length; i++) {
            if  ((l[i].hostname != "docs.google.com")
              && (l[i].hostname != "b.hatena.ne.jp")
              && (l[i].className != 'ujspdflk')) {
                var logo = document.createElement("img");
                logo.src ='moz-icon://.pdf?size=16';
                logo.border = 0;
                logo.style.margin = '0';
                logo.style.padding = '0';
                var orgpdf = document.createElement("a");
                orgpdf.href = l[i].href;
                orgpdf.className = 'ujspdflk';
                orgpdf.insertBefore(logo, orgpdf.firstChild);
                l[i].href = 'http://docs.google.com/viewer?url=' + l[i].href;
                l[i].target = '_blank';
                l[i].parentNode.insertBefore(orgpdf, l[i].nextSibling);
            }
        }
    }
    document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
        var node = evt.target;
        handle(node);
    }, false);
    handle(document);
})();

青い背景の部分が前回との相違点というか参考元からのコピペ。

動作は

Firefox 3.6.10
userChromeJS 1.2
Sub-Script/Overlay Loader v3.0.29mod
userContent.js_1.3 mod6
AutoPagerize 0.0.43

Firefox 4.0b7pre
userChromeJS 1.2
Sub-Script/Overlay Loader v3.0.29mod
UserScriptLoader.uc.js 0.0.9pre
AutoPagerize 0.0.43

で確認しましたが、ご利用は自己責任で。