Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created September 10, 2009 07:55
Show Gist options
  • Save hail2u/184401 to your computer and use it in GitHub Desktop.
Save hail2u/184401 to your computer and use it in GitHub Desktop.

Revisions

  1. hail2u revised this gist Nov 6, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    (function () {
    function addLink (d) {
    Array.forEach(d.getElementsByTagName("a"), function (a) {
    if (a.href.match(/\.(pdf|ppt|tiff?)$/i) && !a.href.match(/q=related:/)) {
    if (a.href.match(/\.(pdf|ppt|tiff?)$/i) && !a.href.match(/docs\.google\.com/) && !a.href.match(/q=related:/i)) {
    var gdico = document.createElement("img");
    gdico.setAttribute("src", "http://docs.google.com/favicon.ico");
    gdico.setAttribute("style", "border:none;");
  2. hail2u revised this gist Nov 6, 2009. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@
    // @name View PDF/PPT/TIFF with Google Document Viewer
    // @namespace http://hail2u.net/
    // @description Insert a Google Docs icon for viewing PDF/PPT/TIFF with Google Document Viewer.
    // @include http://*
    // @include https://*
    // @exclude http://docs.google.com/*
    // ==/UserScript==

  3. hail2u revised this gist Nov 6, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    gdico.setAttribute("src", "http://docs.google.com/favicon.ico");
    gdico.setAttribute("style", "border:none;");
    var gdv = document.createElement("a");
    gdv.setAttribute("href", "http://docs.google.com/gview?url=" + encodeURIComponent(a.href) + "&a=b");
    gdv.setAttribute("href", "http://docs.google.com/gview?url=" + encodeURIComponent(a.href) + "&hl=ja");
    gdv.appendChild(gdico);
    a.parentNode.insertBefore(gdv, a.nextSibling);
    a.parentNode.insertBefore(document.createTextNode(" "), a.nextSibling);
  4. hail2u revised this gist Nov 1, 2009. 1 changed file with 30 additions and 4 deletions.
    34 changes: 30 additions & 4 deletions view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -28,10 +28,36 @@
    }, false);

    if (typeof LDR !== undefined) {
    unsafeWindow.register_hook('before_printfeed', function (feed) {
    feed.items.forEach(function (item) {
    addLink(item.body);
    });
    var w = unsafeWindow;

    var watcher = {
    callAddLink: function (d) {
    this.cancel();
    addLink(d);
    },

    setup: function (feed) {
    this.cancel();
    var item_count = feed.items.length;
    var d = document.getElementById("right_container");
    var self = this;
    this.timeoutID = setInterval(function () {
    if (d.getElementsByClassName("item").length === item_count) {
    self.callAddLink(d);
    }
    }, 1000);
    },

    cancel: function () {
    if (typeof this.timeoutID === "number") {
    clearInterval(this.timeoutID);
    delete this.timeoutID;
    }
    }
    };

    w.register_hook('after_printfeed', function (feed) {
    watcher.setup(feed);
    });
    }
    })();
  5. hail2u revised this gist Nov 1, 2009. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,15 @@

    addLink(document);

    document.body.addEventListener('AutoPagerize_DOMNodeInserted', function (evt) {
    addLink(evt.target);
    document.body.addEventListener('AutoPagerize_DOMNodeInserted', function (e) {
    addLink(e.target);
    }, false);

    if (typeof LDR !== undefined) {
    unsafeWindow.register_hook('before_printfeed', function (feed) {
    feed.items.forEach(function (item) {
    addLink(item.body);
    });
    });
    }
    })();
  6. hail2u revised this gist Oct 20, 2009. 1 changed file with 23 additions and 9 deletions.
    32 changes: 23 additions & 9 deletions view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,29 @@
    // ==UserScript==
    // @name View PDF/PPT with Google Document Viewer
    // @name View PDF/PPT/TIFF with Google Document Viewer
    // @namespace http://hail2u.net/
    // @description Insert a "[GDV]" link for viewing PDF/PPT with Google Document Viewer.
    // @description Insert a Google Docs icon for viewing PDF/PPT/TIFF with Google Document Viewer.
    // @exclude http://docs.google.com/*
    // ==/UserScript==

    Array.forEach(document.getElementsByTagName("a"), function (a) {
    if (a.href.match(/\.(pdf|ppt)$/)) {
    var gdv = document.createElement("a");
    gdv.setAttribute("href", "http://docs.google.com/gview?url=" + encodeURIComponent(a.href) + "&a=b");
    gdv.appendChild(document.createTextNode("[GDV]"));
    a.parentNode.insertBefore(gdv, a.nextSibling);
    (function () {
    function addLink (d) {
    Array.forEach(d.getElementsByTagName("a"), function (a) {
    if (a.href.match(/\.(pdf|ppt|tiff?)$/i) && !a.href.match(/q=related:/)) {
    var gdico = document.createElement("img");
    gdico.setAttribute("src", "http://docs.google.com/favicon.ico");
    gdico.setAttribute("style", "border:none;");
    var gdv = document.createElement("a");
    gdv.setAttribute("href", "http://docs.google.com/gview?url=" + encodeURIComponent(a.href) + "&a=b");
    gdv.appendChild(gdico);
    a.parentNode.insertBefore(gdv, a.nextSibling);
    a.parentNode.insertBefore(document.createTextNode(" "), a.nextSibling);
    }
    });
    }
    });

    addLink(document);

    document.body.addEventListener('AutoPagerize_DOMNodeInserted', function (evt) {
    addLink(evt.target);
    }, false);
    })();
  7. hail2u created this gist Sep 10, 2009.
    15 changes: 15 additions & 0 deletions view-with-gdv.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // ==UserScript==
    // @name View PDF/PPT with Google Document Viewer
    // @namespace http://hail2u.net/
    // @description Insert a "[GDV]" link for viewing PDF/PPT with Google Document Viewer.
    // @exclude http://docs.google.com/*
    // ==/UserScript==

    Array.forEach(document.getElementsByTagName("a"), function (a) {
    if (a.href.match(/\.(pdf|ppt)$/)) {
    var gdv = document.createElement("a");
    gdv.setAttribute("href", "http://docs.google.com/gview?url=" + encodeURIComponent(a.href) + "&a=b");
    gdv.appendChild(document.createTextNode("[GDV]"));
    a.parentNode.insertBefore(gdv, a.nextSibling);
    }
    });