-
-
Save kurumigi/188377 to your computer and use it in GitHub Desktop.
[GM script]View PDF/PPT with Google Document Viewer (with AutoPagerize)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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