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.).

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         PDF Background Color Controller
// @namespace    http://tampermonkey.net/
// @version      0.7
// @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==

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: 100000;
    `;
    var cover = document.createElement("div");
    cover.setAttribute("style", css);
    return cover;
}

function renderPage(url, panelSelector) {
    if (window.location.href.includes(url)) {
        var cover = get_cover();
        var scope = document.querySelector(panelSelector);
        //console.log(scope);
        if (scope === null) {
            setTimeout(() => renderPage(url, panelSelector), 1000); // Retry after 1 second
        } else {
            scope.appendChild(cover);
        }
    }
}

(function() {
    'use strict';

    renderPage("https://www.overleaf.com/project/", "div.ide-react-panel[data-panel-id='panel-pdf']"); // Call renderPage for possible Overleaf pages
    renderPage("https://docs.google.com/", "div.kix-scrollareadocumentplugin.docs-ui-hit-region-surface"); // Call renderPage for possible Overleaf pages

    var embed = document.querySelector("embed");
    if ((embed !== null && embed.type == "application/pdf") || (typeof pdfjsLib !== "undefined") || (window.location.href.includes(".pdf"))) {
        var cover = get_cover();
        document.body.appendChild(cover);
    }
})();