2009年11月22日日曜日

PDFをGoogle Docsで開く、Chromiumの拡張機能を作る。

参考ページ

ChromiumでPDFをどうやって開くか分からなかったので、作ったんですがAdobe Readerより軽くていい。Linux版のAdobe Readerは重すぎてやってられない。

manifest.json
{
  "name": "OpenPDF",
  "version": "0.1",
   "content_scripts": [ {
      "js": [ "background.js" ],
      "matches": [ "http://*/*", "https://*/*" ]
   } ],
  "description": "Open PDF by Google Docs",
  "background_page": "background.html",
  "permissions": ["tabs", "http://*/*", "https://*/*" ]
}
background.js
var op = {//OpenPdf
 init: function()
 {
   var anchors = document.getElementsByTagName("a");
   for(var i = 0;i < anchors.length;i++){
     if(anchors[i].href.indexOf(".pdf")!=-1 || anchors[i].href.indexOf(".PDF")!=-1){
       var link = 'http://docs.google.com/viewer?url='+anchors[i].href;
       anchors[i].href = link;
     }
   }
 }
}
op.init();//Entry Point
background.html
<html>
<head>

</head>
<body>
background
</body>
</html>

0 件のコメント:

コメントを投稿