Advertisement
Kawiesh

Online Doc Viewer [Bookmarklet]

May 13th, 2021 (edited)
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let
  2. links= document.querySelectorAll("a"),
  3. drive= "https://docs.google.com/viewer?url=",
  4. regex= /.+\.pdf|\.doc|\.docx|\.xls|\.xlsx|\.ppt|\.pptx/i;
  5.  
  6. links.forEach(link => {
  7. link.removeAttribute("ping");
  8. if (regex.test(link.href)){
  9. link.onclick=()=>{
  10. location.href= drive + link.href;
  11. return false;
  12. };
  13. }
  14. });
  15.  
  16. //--------------
  17.  
  18. let
  19. links= document.querySelectorAll("a"),
  20. drive= "https://docs.google.com/viewer?url=",
  21. regex= /.+\.pdf|\.doc|\.docx|\.xls|\.xlsx|\.ppt|\.pptx/i;
  22.  
  23. links.forEach(link => {
  24. if (regex.test(link.href)){
  25. if (location.hostname=="google.com"){
  26. let
  27. gurl= encodeURIComponent(link),
  28. gpar= new URLSearchParams(gurl),
  29. url= gpar.get('url');
  30.  
  31. link.href= drive + url;
  32. }
  33. else{
  34. link.href= drive + link.href;
  35. }
  36. }
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement