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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         PDF Background Color Controller
// @namespace    http://tampermonkey.net/
// @version      0.1
// @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.
// @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: fixed;
            pointer-events: none;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            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'\"]");
        scope.appendChild(cover);
    }else if ((embed !== null && embed.type == "application/pdf") || (typeof pdfjsLib !== "undefined")){
        cover = get_cover();
        document.body.appendChild(cover);
    }
})();