Skip to content

Instantly share code, notes, and snippets.

@otsune
Created January 24, 2010 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otsune/285202 to your computer and use it in GitHub Desktop.
Save otsune/285202 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name PDF/PPT viewer with Google docs
// @namespace http://www.otsune.com/
// @include http://*
// @include https://*
// @exclude http://docs.google.com/*
// @version 0.3
// ==/UserScript==
// Based on http://d.hatena.ne.jp/blooo/20100118/1263818555
// http://coderepos.org/share/browser/lang/javascript/userscripts/pdfppt_viewer_with_google.user.js?
(function() {
if (location.hostname == "docs.google.com") return;
function handle(node){
var items = node.querySelectorAll('a[href$=".pdf"], a[href$=".ppt"]');
for (var i = 0; i < items.length; i++) {
var item = items[i];
if ( (item.hostname != "docs.google.com") &&
(item.hostname != "b.hatena.ne.jp") ) {
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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment