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, overleaf's pdf reviewer and your local files (Please allow the Tampermonkey to access file urls in browser's setting by going to chrome://extensions/, and set Allow access to file URLs.).

当前为 2023-08-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         PDF Background Color Controller
// @namespace    http://tampermonkey.net/
// @version      0.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, overleaf's pdf reviewer and your local files (Please allow the Tampermonkey to access file urls in browser's setting by going to chrome://extensions/, and set Allow access to file URLs.).
// @author       Maple
// @match        *://*/*
// @icon         https://icon-icons.com/downloadimage.php?id=130274&root=2107/ICO/64/&file=file_type_pdf_icon_130274.ico
// @grant        none
// @license MIT
// ==/UserScript==

// The cover should be put as a child of the parent of the element that should be covered.
function get_cover(){
    let css = `
            position: absolute;
            pointer-events: none;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #FDF6E3;
            mix-blend-mode: multiply;
            z-index: 1;
        `;
    var cover = document.createElement("div");
    cover.setAttribute("style", css);
    return cover;
}

(function() {
    'use strict';

    var embed = document.querySelector("embed");
    if(window.location.href.includes("https://www.overleaf.com/project/")){
        var cover = get_cover();
        var scope = document.querySelector("[ng-if=\"ui.pdfLayout == 'sideBySide'\"]");
        //var scope = document.querySelector("canvas").parentElement.parentElement.parentElement;
        scope.appendChild(cover);
    }else if ((embed !== null && embed.type == "application/pdf") || (typeof pdfjsLib !== "undefined") || (window.location.href.includes(".pdf"))){
        cover = get_cover();
        document.body.appendChild(cover);
    }
})();