Autonomous Browser

Automatic browser. This script randomly visits links. To which adventure will it lead you?

目前为 2025-01-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Autonomous Browser
  3. // @description Automatic browser. This script randomly visits links. To which adventure will it lead you?
  4. // @author Schimon Jehudah, Adv.
  5. // @namespace i2p.schimon.autonomous-browser
  6. // @homepageURL https://greasyfork.org/scripts/524715-autonomous-browser
  7. // @supportURL https://greasyfork.org/scripts/524715-autonomous-browser/feedback
  8. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  9. // @license MIT; https://opensource.org/licenses/MIT
  10. // @version 23.03
  11. // @run-at document-start
  12. // @match *://*/*
  13. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5ay77iPPC90ZXh0Pjwvc3ZnPgo=
  14. // ==/UserScript==
  15.  
  16. // icons: ꔮ 🛞 🖱️ 🚷 👆
  17.  
  18. // brands: auto driver, auto pilot, autonomous browser, cruise control, driver-less browser, robotic browser, robotic web (robo-web), self-driving browser, self-driving web, uncrewed browser, unmanned browser, user-less browser
  19.  
  20. // blacklist: anything that has 1 to 7 characters must
  21. // whitelist: anything html.
  22. // anything that has 3 - 4 letters and contains html
  23. // note: not xhtml because of its strikness
  24.  
  25. // load view-source: + link
  26. // /questions/1815021/programmatically-open-view-source-html-window-in-browser-with-javascript
  27.  
  28. /*
  29. setInterval(function() {
  30. links = document.querySelectorAll('a[href]');
  31. link = links[Math.floor(Math.random()*links.length)];
  32. link.click()
  33. }, 10000
  34. );
  35. */
  36.  
  37. //about:srcdoc
  38. //if (isBlacklisted(location.href)) history.back();
  39.  
  40. setInterval(function() {
  41. history.back()
  42. }, 40000);
  43.  
  44. let contentReady = new Promise(function(resolve, reject) {
  45. //setTimeout(console.log('wait'), 10000)
  46. let request = new XMLHttpRequest();
  47. try {
  48. request.open('GET', location.href);
  49. request.onload = function() {
  50. if (request.status == 200) {
  51. resolve(request);
  52. console.log('contentReady.resolve()')
  53. } else {
  54. //alert('(request.status == 200) else')
  55. //history.back();
  56. }
  57. };
  58. //request.onprogress = function() {introPageLoader()};
  59. //request.onprogress = (event) => {introPageLoader()};
  60. request.onerror = function() {
  61. if (request.status == 403) {
  62. //alert('if (request.status == 403)')
  63. history.back();
  64. } else if (request.status == 404) {
  65. history.back();
  66. //alert('if (request.status == 404)')
  67. } else {
  68. //alert('else request.onerror')
  69. history.back();
  70. }
  71. };
  72. // try {request.send();} catch {history.back();}
  73. // Failed to load resource: the server responded with a status of 403 ()
  74. request.send();
  75. } catch {
  76. history.back();
  77. }
  78. });
  79.  
  80. contentReady.then(
  81. function(request) {
  82. console.log('contentReady.then()')
  83. rawDocument = pageLoader(request);
  84. if (!isHTML()) {
  85. //alert('!isHTML()')
  86. history.back();
  87. }
  88. var drive = setInterval(
  89. approveLink,
  90. 10000,
  91. rawDocument
  92. );
  93. },
  94. function(error) {
  95. history.back();
  96. }
  97. );
  98.  
  99. const tldList = [
  100. -2131357492,
  101. -2095271699,
  102. -1830313082,
  103. -1752349395,
  104. -1610658671,
  105. -1542825754,
  106. -1536293812,
  107. -1473409395,
  108. -1426426751,
  109. -1328826067,
  110. -1311829293,
  111. -779965899,
  112. -679381487,
  113. -657310838,
  114. -633654849,
  115. -373274299,
  116. -364826023,
  117. -138012666,
  118. -88694192,
  119. -78033866,
  120. 107861201,
  121. 110087831,
  122. 413633535,
  123. 533748962,
  124. 667475342,
  125. 736767581,
  126. 1052592056,
  127. 1078179023,
  128. 1701667746,
  129. 1942548305,
  130. 1985010934,
  131. 1078179023,
  132. -657310838,
  133. 112291595,
  134. -478448338,
  135. 1242938149,
  136.  
  137. ];
  138.  
  139. // Javascript implementation of Java’s String.hashCode() method
  140. String.prototype.hashCode = function(){
  141. var hash = 0;
  142. if (this.length == 0) return hash;
  143. for (i = 0; i < this.length; i++) {
  144. char = this.charCodeAt(i);
  145. hash = ((hash<<5)-hash)+char;
  146. hash = hash & hash; // Convert to 32bit integer
  147. }
  148. return hash;
  149. }
  150. // Manwe Security Consulting
  151.  
  152. function pageLoader(request) {
  153. console.log('pageLoader()')
  154. const domParser = new DOMParser();
  155. const rawDocument = domParser.parseFromString(request.responseText, 'text/html');
  156. cssSelectors = [
  157. 'audio', 'embed', 'form', 'iframe', 'input',
  158. 'script', 'select', 'style', 'textarea', 'video'
  159. ];
  160. for (let i = 0; i < cssSelectors.length; i++) {
  161. console.log(cssSelectors[i])
  162. for (const item of rawDocument.querySelectorAll(cssSelectors[i])) {item.remove()}
  163. }
  164. const insertDocument = document.importNode(rawDocument.documentElement, true);
  165. const removeDocument = document.documentElement;
  166. try {
  167. document.replaceChild(insertDocument, removeDocument);
  168. } catch {
  169. history.back();
  170. }
  171. return rawDocument;
  172. }
  173.  
  174. function approveLink(rawDocument) {
  175. console.log('approveLink()')
  176. link = pickURL(rawDocument);
  177.  
  178. if (link) {
  179. link = link.href;
  180. } else {
  181. history.back();
  182. }
  183.  
  184. //// alert('link1: ' + link)
  185. switch (true) {
  186. case (link.endsWith('/')):
  187. case (link.endsWith('.php')):
  188. case (link.endsWith('.htm')):
  189. case (link.endsWith('.html')):
  190. break;
  191. case (isFileExtension(link)):
  192. case (isBlacklisted(link)):
  193. case (link.includes(':') && !link.startsWith('http')): // NOTE consider HTTPS
  194. //history.back();
  195. link = null;
  196. break;
  197. }
  198. //// alert('* / ' + link.endsWith('/') + ' * php ' + link.endsWith('.php') + ' * htm ' + link.endsWith('.htm') + ' * html ' + link.endsWith('.html') + ' * isFileExtension(link) ' + isFileExtension(link) + ' * isBlacklisted(link) ' + isBlacklisted(link) + ' * link.includes(: and not start with http ' + (link.includes(':') && !link.startsWith('http')))
  199. //// alert('link2: ' + link)
  200.  
  201. if (link) {
  202. window.open(link, '_self');
  203. } else {
  204. history.back();
  205. }
  206.  
  207. }
  208.  
  209. function isHTML() {
  210. console.log('isHTML()')
  211. if (document.contentType == 'text/html') {
  212. return true;
  213. }
  214. }
  215.  
  216. function pickURL(rawDocument) {
  217. console.log('pickURL()')
  218. links = rawDocument.querySelectorAll('a[href]');
  219. //if (links.length < 3) {return;}
  220. link = links[Math.floor(Math.random()*links.length)];
  221. return link;
  222. }
  223.  
  224. function isFileExtension(link) {
  225. console.log('isFileExtension()')
  226. partedURL = link.split('/');
  227. console.log(partedURL)
  228. lastAfterSlash = partedURL[partedURL.length-1];
  229. console.log(lastAfterSlash)
  230. dot = lastAfterSlash.lastIndexOf('.');
  231. console.log(dot)
  232. if (dot < 0) {return;}
  233. fileExtension = lastAfterSlash.slice(dot);
  234. console.log(fileExtension)
  235. if (fileExtension.length < 8) {
  236. console.log('return true')
  237. return true;
  238. }
  239. }
  240.  
  241. function isBlacklisted(link) {
  242. console.log('isBlacklisted()')
  243. console.log(link)
  244. host = new URL(link).host;
  245. hostParted = host.split('.');
  246. tld = hostParted[hostParted.length-2] + '.' + hostParted[hostParted.length-1];
  247. tldHash = tld.hashCode();
  248. if (tldList.includes(tldHash)) {
  249. return true;
  250. }
  251. }