Read Website Content like a Web Crawler

It can let you to read the content you searched in Google.

Od 15.10.2021.. Pogledajte najnovija verzija.

// ==UserScript==
// @name         Read Website Content like a Web Crawler
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  It can let you to read the content you searched in Google.
// @author       You
// @match        https://medium.com/*
// @match        http://webcache.googleusercontent.com/search?q=*
// @match        https://webcache.googleusercontent.com/search?q=*
// @icon         https://upload.cc/i1/2021/10/15/1zIbtQ.png
// @grant        GM_registerMenuCommand
// @run-at       document-start
// ==/UserScript==
(function() {
  'use strict';

  function turnPlain() {
    const url = location.href;
    location.href = `https://webcache.googleusercontent.com/search?q=cache:${encodeURI(url)}&strip=1&vwsrc=0`
  }

  function turnCrawler() {
    const url = location.href;
    location.href = `https://webcache.googleusercontent.com/search?q=cache:${encodeURI(url)}`
  }

  function isValidCachePage() {
    const m = /https?\:\/\/webcache\.googleusercontent\.com\/search\?(\S+)$/.exec(location.href)
    if (m && m[1] && typeof m[1] == 'string') {
      const params = new URLSearchParams(m[1]);
      const q = params.get('q')
      if (q && typeof q == 'string') {
        const m2 = /^cache:(https?\:\/\/\S+)$/.exec(q)
        if (m2 && m2[1] && typeof m2[1] == 'string') {
          let url;
          try {
            url = decodeURI(m2[1]);
          } catch (e) {
            url = m2[1];
          }
          return url;
        }
      }
    }
    return '';
  }

  function turnOriginal() {
    if (!cacheUrl) return;
    const url = cacheUrl;
    location.href = `${url}`
  }
  let cacheUrl = ''

  if (!/^https?\:\/\/webcache\.googleusercontent\.com\//.test(location.href)) {

    new Promise(() => {
      GM_registerMenuCommand("Read Plain Content", turnPlain, "P");
      GM_registerMenuCommand("Read like Web Crawler", turnCrawler, "C");
    })

  } else {
    cacheUrl = isValidCachePage();

    if (cacheUrl) {

      const jb = {};

      const mc = (key) => {
        return {
          get() {
            throw `document.${key}`;
          },
          set(newValue) {},
          enumerable: true,
          configurable: false
        }
      }

      for (const key of ['documentElement', 'querySelector', 'querySelectorAll']) {
        jb[key] = mc(key)
      }

      Object.defineProperties(document, jb);

      new Promise(() => {
        GM_registerMenuCommand("Read Original", turnOriginal, "O");
      })

    }



  }




  // Your code here...
})();