Immersive Reader

Read in Immersive Reader

Ekde 2022/04/26. Vidu La ĝisdata versio.

// ==UserScript==
// @name         Immersive Reader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Read in Immersive Reader
// @author       You
// @match        https://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=readfog.com
// @grant        GM_registerMenuCommand
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';

  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 = `read://${url}`

    let mystring = `<html><a href="${nurl}">Drag me to url for Immersive Reader</a></html>`;
      let myblob = new Blob([mystring], {
          type: 'text/html'
      });
      mystring = "";
      let murl = URL.createObjectURL(myblob);

   location.href = murl
  }

  function turnOriginal() {
    const url = location.href.replace(/^read:\/\//,'');
    location.href = `${url}`
  }

  if (!/^read:\/\//.test(location.href)) {

    new Promise(() => {
      GM_registerMenuCommand("Switch to Immersive Reader", turnPlain, "I");
    })

  } else {

      new Promise(() => {
        GM_registerMenuCommand("Switch to Normal", turnOriginal, "N");
      })

  }





})();