Read Website Content like a Web Crawler

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

  1. // ==UserScript==
  2. // @name Read Website Content like a Web Crawler
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description It can let you to read the content you searched in Google.
  6. // @author CY Fung
  7. // @match https://*/*
  8. // @match http://webcache.googleusercontent.com/search?q=*
  9. // @match https://webcache.googleusercontent.com/search?q=*
  10. // @icon https://upload.cc/i1/2021/10/15/1zIbtQ.png
  11. // @grant GM_registerMenuCommand
  12. // @run-at document-start
  13. // @license MIT
  14. // ==/UserScript==
  15. (function() {
  16. 'use strict';
  17.  
  18. function getPageURL(url) {
  19. if (typeof url != 'string') return null;
  20. const m1 = /^https:\/\/www\.signalhire\.com\/sorry\?continue=([^=&]+)/.exec(url);
  21. let eurl = ''; // URIComponent
  22. if (m1) eurl = m1[1];
  23. try {
  24. if (eurl && typeof eurl == 'string') url = decodeURIComponent(eurl); // avoid URI malformed
  25. } catch (e) {}
  26. return url;
  27. }
  28.  
  29. function turnPlain() {
  30. const url = getPageURL(location.href);
  31. location.href = `https://webcache.googleusercontent.com/search?q=cache:${encodeURI(url)}&strip=1&vwsrc=0`; //not encodeURIComponent
  32. }
  33.  
  34. function turnCrawler() {
  35. const url = getPageURL(location.href);
  36. location.href = `https://webcache.googleusercontent.com/search?q=cache:${encodeURI(url)}`; //not encodeURIComponent
  37. }
  38.  
  39. function isValidCachePage() {
  40. const m = /https?\:\/\/webcache\.googleusercontent\.com\/search\?(\S+)$/.exec(location.href)
  41. if (m && m[1] && typeof m[1] == 'string') {
  42. const params = new URLSearchParams(m[1]);
  43. const q = params.get('q')
  44. if (q && typeof q == 'string') {
  45. const m2 = /^cache:([a-zA-Z0-9]+:)?(https?\:\/\/\S+)\s*$/.exec(q)
  46. const m2URL = m2 ? m2[2] : null
  47. if (m2URL && typeof m2URL == 'string') {
  48. let url;
  49. try {
  50. url = decodeURI(m2URL);
  51. } catch (e) {
  52. url = m2URL;
  53. }
  54. return url;
  55. }
  56. }
  57. }
  58. return '';
  59. }
  60.  
  61. function turnOriginal() {
  62. if (!cacheUrl) return;
  63. const url = cacheUrl;
  64. location.href = `${url}`
  65. }
  66. let cacheUrl = ''
  67.  
  68. if (!/^https?\:\/\/webcache\.googleusercontent\.com\//.test(location.href)) {
  69.  
  70. new Promise(() => {
  71. GM_registerMenuCommand("Read Plain Content", turnPlain, "P");
  72. GM_registerMenuCommand("Read like Web Crawler", turnCrawler, "C");
  73. })
  74.  
  75. } else {
  76. cacheUrl = isValidCachePage();
  77.  
  78. if (cacheUrl) {
  79.  
  80. const { documentElement } = document
  81.  
  82. const jb = {};
  83.  
  84. const mc = (key) => {
  85. return {
  86. get() {
  87. throw `document.${key}`;
  88. },
  89. set(newValue) {},
  90. enumerable: true,
  91. configurable: false
  92. }
  93. }
  94.  
  95. for (const key of ['documentElement', 'querySelector', 'querySelectorAll']) {
  96. jb[key] = mc(key)
  97. }
  98.  
  99. const constVal = (value) => {
  100. return {
  101. value,
  102. enumerable: true,
  103. configurable: false
  104.  
  105. }
  106. }
  107.  
  108. try {
  109. Object.defineProperties(document, jb);
  110. } catch (e) {}
  111.  
  112. try {
  113. Object.defineProperties(navigator, {
  114. 'userAgent': constVal('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'),
  115. 'vendor': constVal(""),
  116. 'platform': constVal(""),
  117. 'appCodeName': constVal(""),
  118. 'appName': constVal(""),
  119. 'appVersion': constVal(""),
  120. 'product': constVal(""),
  121. 'productSub': constVal(""),
  122. 'language': constVal(""),
  123. 'languages': constVal([]),
  124. 'geolocation': constVal(null),
  125. 'doNotTrack': constVal(null),
  126. 'pdfViewerEnabled': constVal(false),
  127. 'plugins': constVal(null),
  128. });
  129.  
  130. } catch (e) {}
  131.  
  132. requestAnimationFrame(() => {
  133.  
  134.  
  135. // Web Crawler don't like fixed elements
  136. addStyle(`
  137. html body div[class|="fixed"], html body div[class*="-fixed "], html body div[class$="-fixed"]{
  138. top:auto !important; right:auto !important; left:auto !important; bottom:auto !important;
  139. }
  140. `, documentElement);
  141.  
  142. });
  143.  
  144. new Promise(() => {
  145. GM_registerMenuCommand("Read Original", turnOriginal, "O");
  146. })
  147.  
  148. }
  149.  
  150. }
  151.  
  152. function addStyle(styleText, container) {
  153. const styleNode = document.createElement('style');
  154. //styleNode.type = 'text/css';
  155. styleNode.textContent = styleText;
  156. (container || document.documentElement).appendChild(styleNode);
  157. return styleNode;
  158. }
  159.  
  160. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址