Online Document Viewer

Open documents in Google docs!

当前为 2021-05-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Online Document Viewer
// @namespace   Online Document Viewer
// @match       *://*/*
// @grant       none
// @version     1.0
// @author      K.D.
// @description Open documents in Google docs!
// ==/UserScript==

let drive= "https://docs.google.com/viewer?url=",
regex= /.+\.pdf|\.doc|\.docx|\.xls|\.xlsx|\.ppt|\.pptx/i;

function main(a){

a.onclick=()=>{
if(regex.test(a.href)){
   location.href= drive + a.href;
   return false;
}
else{
   location.href= a.href;
   return false;   
}
};    
}   

let google= /google\..+?\/search\?q=/i;
if(google.test("location.href")){
let gLinks= document.querySelectorAll(".Zu0yb.UGIkD.qzEoUe");
gLinks.forEach(link => {
let gURL= link.closest("a");
    gURL.removeAttribute("ping");
setInterval(main(gURL), 2000);
});
}
else{
let allLinks= document.querySelectorAll("a");
allLinks.forEach(link => {
setInterval(main(link), 2000);
});
}