Immersive Reader

Read in Immersive Reader

< Feedback de Immersive Reader

Avaliação: Mau - o script não funciona

§
Publicado: 23/08/2026

Userscript immersive not working for Firefox based browsers. Firefox based browsers use urls starting with about:reader?url= for immersive readers.

Suggested code:

// ==UserScript==
// @name         Immersive Reader
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Read in Immersive Reader
// @author       You
// @match        https://*/*
// @match        http://*/*
// @match        read://*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=readfog.com
// @grant        GM_registerMenuCommand
// @grant        GM.openInTab
// @grant        GM.setClipboard
// @run-at       document-start
// @license      MIT
// @downloadURL  https://update.greasyfork.org/scripts/444034/Immersive%20Reader.user.js
// @updateURL    https://update.greasyfork.org/scripts/444034/Immersive%20Reader.meta.js
// ==/UserScript==

(function () {
    'use strict';

    const userAgent = navigator.userAgent.toLowerCase();
    const firefoxBrowsers = ["firefox"];
    let isFirefox = false;
    for (let i = 0; i < firefoxBrowsers.length; i++) {
        if (userAgent.includes(firefoxBrowsers[i])) {
            isFirefox = true;
        }
    }

    function getPageURL(url) {
        if (typeof url != 'string') return null;
        const m1 = /^https:\/\/www\.signalhire\.com\/sorry\?continue=([^=&]+)/.exec(url);
        let eurl = ''; // URIComponent
        if (m1) eurl = m1[1];
        try {
            if (eurl && typeof eurl == 'string') url = decodeURIComponent(eurl); // avoid URI malformed
        } catch (e) { }
        return url;
    }

    function turnPlain() {
        const url = getPageURL(location.href);
        const nurl = isFirefox ? `about:reader?url=${url}` : `read://${url}`;

        if (!isFirefox) {
            GM.openInTab(nurl, false);
            return 0;
        }

        const newDiv = document.createElement("div");
        newDiv.innerHTML = 'for security reasons Firefox browsers disallow scripts<br>opening `about:` urls (<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/create#:~:text=security%20reasons" target="_blank">Mozilla docs</a>, <a href="https://violentmonkey.github.io/api/gm/#gm_openintab:~:text=Note%20that%20Firefox%20disallows%20data%3A%2C%20blob%3A%2C%20chrome%3A%2C%20file%3A%2C%20and%20many%20about%3A%20URLs" target="_blank">Violent Monkey docs</a>)<br><br>Click the following button to copy the url (and press <kbd>ctrl</kbd>+<kbd>L</kbd> to focus on url bar))<br>';
        newDiv.style.textAlign = "center";
        newDiv.style.position = "fixed";
        newDiv.style.top = "50%";
        newDiv.style.left = "50%";
        newDiv.style.transform = "translate(-50%, -50%)";
        newDiv.style.backgroundColor = "lightgreen";
        newDiv.style.color = "black";
        newDiv.style.padding = "10px";
        newDiv.style.borderRadius = "20px";
        newDiv.style.transition = "opacity 2s ease-in-out";
        document.body.appendChild(newDiv);

        const copyBtn = document.createElement("button");
        copyBtn.id = "immersiveReaderCopyBtn";
        copyBtn.innerHTML = "Click this div to obviously copy the url";
        copyBtn.style.border = "none";
        copyBtn.style.borderRadius = "10px";
        copyBtn.style.width = "100%";
        copyBtn.style.height = "50px";
        newDiv.appendChild(copyBtn);

        const styleTag = document.createElement("style");
        styleTag.innerHTML = "#immersiveReaderCopyBtn { background-color: #7ccc7c } #immersiveReaderCopyBtn:hover { background-color: #6cb26c } #immersiveReaderCopyBtn:active { background-color: #4d7f4d }";
        newDiv.appendChild(styleTag);
        copyBtn.addEventListener("click", () => {
            new GM.setClipboard(nurl, "text");
            newDiv.remove();
        });
    }

    if (!/^read:\/\//.test(location.href)) {
        new Promise(() => { GM_registerMenuCommand("Switch to Immersive Reader", turnPlain, "I") });
    }
})();

Publicar resposta

Inicie sessão para publicar uma resposta.