PDF Background Color Controller

This script can change the backgroud color for the pdf files opened by your brower. It is applicable for Chrome build-in PDF viewer, pdf.js and overleaf's pdf reviewer.

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

  1. // ==UserScript==
  2. // @name PDF Background Color Controller
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description This script can change the backgroud color for the pdf files opened by your brower. It is applicable for Chrome build-in PDF viewer, pdf.js and overleaf's pdf reviewer.
  6. // @author Maple
  7. // @match *://*/*
  8. // @icon https://icon-icons.com/downloadimage.php?id=130274&root=2107/ICO/64/&file=file_type_pdf_icon_130274.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. // The cover should be put as a child of the parent of the element that should be covered.
  14. function get_cover(){
  15. let css = `
  16. position: fixed;
  17. pointer-events: none;
  18. top: 0;
  19. left: 0;
  20. width: 100vw;
  21. height: 100vh;
  22. background-color: #FDF6E3;
  23. mix-blend-mode: multiply;
  24. z-index: 1;
  25. `;
  26. var cover = document.createElement("div");
  27. cover.setAttribute("style", css);
  28. return cover;
  29. }
  30.  
  31. (function() {
  32. 'use strict';
  33.  
  34. var embed = document.querySelector("embed");
  35. if(window.location.href.includes("https://www.overleaf.com/project/")){
  36. var cover = get_cover();
  37. var scope = document.querySelector("[ng-if=\"ui.pdfLayout == 'sideBySide'\"]");
  38. scope.appendChild(cover);
  39. }else if ((embed !== null && embed.type == "application/pdf") || (typeof pdfjsLib !== "undefined")){
  40. cover = get_cover();
  41. document.body.appendChild(cover);
  42. }
  43. })();