Skip to content

Instantly share code, notes, and snippets.

@kurumigi
Forked from hail2u/view-with-gdv.user.js
Created September 17, 2009 06:38
Show Gist options
  • Save kurumigi/188377 to your computer and use it in GitHub Desktop.
Save kurumigi/188377 to your computer and use it in GitHub Desktop.
[GM script]View PDF/PPT with Google Document Viewer (with AutoPagerize)
// ==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==
(function () {
var excludeUrls = new RegExp([
"^https?://docs\\.google\\.com/",
"^http://b\\.hatena\\.ne\\.jp/(entry(/|\\.\\w+\\?)|\\w+/add\\.confirm)",
].join('|'));
function insertGDVLink(doc) {
var doc = doc || document;
Array.forEach(doc.getElementsByTagName("a"), function (a) {
if (/\.(pdf|ppt|tif)$/.test(a.href)) {
if (!excludeUrls.test(a.href)) {
var gdv = document.createElement("a");
gdv.setAttribute("href", "http://docs.google.com/viewer?url=" + encodeURIComponent(a.href));
gdv.appendChild(document.createTextNode("[GDV]"));
var gdvContainer = document.createElement("span");
gdvContainer.setAttribute("class", "GM_gdv");
gdvContainer.setAttribute("style", "margin-left: 5px; font-size: 80%");
gdvContainer.appendChild(gdv);
a.parentNode.insertBefore(gdvContainer, a.nextSibling);
}
}
});
}
insertGDVLink();
// for AutoPagerize
document.body.addEventListener('AutoPagerize_DOMNodeInserted',function (evt) {
insertGDVLink(evt.target);
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment