浏览器功能包

修改浏览器的一些配置,使脚本可以作弊

安装此脚本?
作者推荐脚本

您可能也喜欢自用算法包

安装此脚本
  1. // ==UserScript==
  2. // @name 浏览器功能包
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.8.1
  5. // @description 修改浏览器的一些配置,使脚本可以作弊
  6. // @author Tenfond
  7. // @match https://*/*
  8. // @match http://*/*
  9. // @grant none
  10. // @license MIT
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. try {
  16. Object.defineProperty(console, "clear", {
  17. value: function () {
  18. console.error("禁止清除控制台");
  19. },
  20. writable: false,
  21. enumerable: true,
  22. configurable: false
  23. });
  24. } catch (e) {
  25. console.error(e.message);
  26. }
  27.  
  28. document.root = document.querySelector(":root");
  29. document.hide = (function () {
  30. const hidden = document.createElement("hidden");
  31. hidden.setAttribute("style", "visibility: hidden; display: none");
  32. document.root.appendChild(hidden);
  33. return function hide(node) {
  34. hidden.appendChild(node);
  35. };
  36. })();
  37.  
  38. try {
  39. const timers = {
  40. "Timeout": {},
  41. "Interval": {}
  42. },
  43. setTimeout = window.setTimeout,
  44. setInterval = window.setInterval,
  45. clearTimeout = window.clearTimeout,
  46. clearInterval = window.clearInterval;
  47. window.setTimeout = function (handler, timeout, ...arguments) {
  48. const handle = setTimeout.apply(this, [handler, timeout].concat(arguments));
  49. timers["Timeout"][handle] = {
  50. "handler": handler,
  51. "timeout": timeout,
  52. "arguments": arguments
  53. };
  54. return handle;
  55. };
  56. window.setInterval = function (handler, timeout, ...arguments) {
  57. const handle = setInterval.apply(this, [handler, timeout].concat(arguments));
  58. timers["Interval"][handle] = {
  59. "handler": handler,
  60. "timeout": timeout,
  61. "arguments": arguments
  62. };
  63. return handle;
  64. };
  65. window.getAllTimeout = function () {
  66. return timers["Timeout"];
  67. };
  68. window.getAllInterval = function () {
  69. return timers["Interval"];
  70. };
  71. window.getTimeout = function (handle) {
  72. return timers["Timeout"][handle];
  73. };
  74. window.getInterval = function (handle) {
  75. return timers["Interval"][handle];
  76. };
  77. window.clearTimeout = function (handle) {
  78. clearTimeout.apply(this, arguments);
  79. delete timers["Timeout"][handle];
  80. };
  81. window.clearInterval = function (handle) {
  82. clearInterval.apply(this, arguments);
  83. delete timers["Interval"][handle];
  84. };
  85. } catch (e) {
  86. console.error(e.message);
  87. }
  88.  
  89. // event 可信任事件
  90. (function () {
  91. try {
  92. const addEventListener = EventTarget.prototype.addEventListener;
  93. Object.defineProperty(EventTarget.prototype, "addEventListener", {
  94. value: function (type, callback, options = false) {
  95. return addEventListener.apply(this, [type, type === "click" ? function (event) {
  96. const object = {};
  97. for (const p in event) {
  98. object[p] = typeof event[p] === "function" ? event[p].bind(event) : event[p];
  99. }
  100. object.isTrusted = true;
  101. arguments[0] = Object.setPrototypeOf(object, event);
  102. return callback.apply(this, arguments);
  103. } : callback, options]);
  104. },
  105. writable: false,
  106. enumerable: true,
  107. configurable: false
  108. });
  109. } catch (e) {
  110. console.error(e.message);
  111. }
  112. })();
  113.  
  114. // 定义 location.hashCode 获取 href的hash值
  115. (function () {
  116. try {
  117. Object.defineProperty(location, "hashCode", {
  118. enumerable: true,
  119. configurable: false,
  120. get: function () {
  121. let code = 0;
  122. for (const v of location.href) {
  123. code += (code << 7) + v.charCodeAt(0);
  124. }
  125. // 返回值在 JavaScript 中的取值范围 [-2147483648,4294967294]
  126. return code;
  127. }
  128. });
  129. } catch (e) {
  130. console.error(e.message);
  131. }
  132. let hashCode = location.hashCode, onchange = null;
  133. try {
  134. Object.defineProperty(location, "onchange", {
  135. enumerable: true,
  136. configurable: false,
  137. get: function () {
  138. return onchange;
  139. },
  140. set: function (handler) {
  141. if (typeof handler === "function" || Boolean(handler) === false) {
  142. onchange = handler;
  143. } else {
  144. console.error("Uncaught (in onchange) TypeError: " + handler + " is not a function.")
  145. }
  146. }
  147. });
  148. setInterval(function () {
  149. if (hashCode !== location.hashCode) {
  150. hashCode = location.hashCode;
  151. if (typeof onchange === "function") onchange();
  152. }
  153. }, 500);
  154. } catch (e) {
  155. console.error(e.message);
  156. }
  157. })();
  158.  
  159. window.searchToJSON = function searchToJSON(search) {
  160. if (search) {
  161. return JSON.parse("{\"" + decodeURIComponent(search.substring(1)
  162. .replace(new RegExp("\"", "g"), '\\"')
  163. .replace(new RegExp("&", "g"), '","')
  164. .replace(new RegExp("=", "g"), '":"')) + "\"}");
  165. } else {
  166. return null;
  167. }
  168. };
  169.  
  170. window.hrefToLocation = function hrefToLocation(href) {
  171. let location = {href: href}, c = 0, start = 0, port, search;
  172. for (let i = 0; i < href.length; i++) {
  173. if (href[i] === "/") {
  174. if (++c === 1) {
  175. location.protocol = href.substring(start, i);
  176. } else if (c === 3) {
  177. location.host = href.substring(start, i);
  178. location.origin = href.substring(0, i);
  179. if (port) {
  180. location.port = href.substring(port, i);
  181. } else {
  182. location.hostname = location.host;
  183. location.port = "";
  184. }
  185. }
  186. if (c <= 3) {
  187. start = i + 1;
  188. }
  189. } else if (href[i] === ":" && c === 2) {
  190. location.hostname = href.substring(start + 1, i);
  191. port = i + 1;
  192. } else if (href[i] === "?" && !search) {
  193. location.pathname = href.substring(start - 1, i);
  194. search = i;
  195. } else if (href[i] === "#" && !location.hash) {
  196. location.hash = href.substring(i);
  197. if (search) {
  198. location.search = href.substring(search, i);
  199. } else {
  200. location.search = "";
  201. location.pathname = href.substring(start - 1, i);
  202. }
  203. break;
  204. }
  205. }
  206. if (typeof location.host === "undefined") {
  207. if (c < 2) {
  208. location.host = location.hostname = location.port = location.origin = "";
  209. } else if (c === 2) {
  210. location.host = href.substring(start);
  211. location.origin = href;
  212. if (typeof location.hostname === "undefined") {
  213. location.hostname = location.host;
  214. location.port = "";
  215. } else {
  216. location.port = href.substring(port);
  217. }
  218. }
  219. location.pathname = location.hash = "";
  220. } else if (typeof location.pathname === "undefined") {
  221. location.pathname = href.substring(start - 1);
  222. location.search = location.hash = "";
  223. } else if (typeof location.search === "undefined") {
  224. if (search) {
  225. location.search = href.substring(search);
  226. } else {
  227. location.search = "";
  228. }
  229. location.hash = "";
  230. } else if (typeof location.hash === "undefined") {
  231. location.hash = "";
  232. }
  233. return location;
  234. };
  235.  
  236. window.xmlHttpRequest = function xmlHttpRequest(handler = {}) {
  237. function xhrToArgs(xhr) {
  238. if (xhr.constructor.name === "XMLHttpRequest") return {
  239. // "onabort": xhr["onabort"],
  240. // "onerror": xhr["onerror"],
  241. // "onload": xhr["onload"],
  242. // "onloadend": xhr["onloadend"],
  243. // "onloadstart": xhr["onloadstart"],
  244. // "onprogress": xhr["onprogress"],
  245. // "onreadystatechange": xhr["onreadystatechange"],
  246. // "ontimeout": xhr["ontimeout"],
  247. "abort": function () {
  248. return xhr["abort"]();
  249. },
  250. "finalUrl": xhr["responseURL"],
  251. "responseHeaders": (function () {
  252. const headers = {};
  253. xhr["getAllResponseHeaders"]().split("\r\n").forEach(function (header) {
  254. header = header.split(": ");
  255. headers[header[0]] = header[1];
  256. });
  257. return headers;
  258. })(),
  259. "getResponseHeader": function (name) {
  260. return xhr["getResponseHeader"](name);
  261. },
  262. "overrideMimeType": function (mime) {
  263. return xhr["overrideMimeType"](mime);
  264. },
  265. "responseType": xhr["responseType"],
  266. "response": xhr["response"],
  267. "responseText": (function () {
  268. try {
  269. return xhr["responseText"];
  270. } catch (e) {
  271. console.error(e.message);
  272. return e;
  273. }
  274. })(),
  275. "responseXML": (function () {
  276. try {
  277. return xhr["responseXML"];
  278. } catch (e) {
  279. console.error(e.message);
  280. return e;
  281. }
  282. })(),
  283. "readyState": xhr["readyState"],
  284. "status": xhr["status"],
  285. "statusText": xhr["statusText"],
  286. "timeout": xhr["timeout"],
  287. // "upload": xhr["upload"],
  288. // "withCredentials": xhr["withCredentials"]
  289. }; else return xhr.constructor.name;
  290. }
  291.  
  292. if (typeof handler === "string") handler = {url: handler};
  293. const request = new XMLHttpRequest();
  294. if (handler.onreadystatechange) request.onreadystatechange = function (event) {
  295. return handler.onreadystatechange(xhrToArgs(request), event);
  296. };
  297. request.open(handler.method ? handler.method.toUpperCase() : "GET", handler.url ? handler.url : location.href, handler.async ? handler.async : true, handler.user ? handler.user : null, handler.password ? handler.password : null);
  298. if (handler.headers) for (let header in handler.headers) request.setRequestHeader(header, handler.headers[header]);
  299. if (handler.onabort) request.onabort = function (event) {
  300. return handler.onabort(xhrToArgs(request), event);
  301. };
  302. if (handler.onerror) request.onerror = function (event) {
  303. return handler.onerror(xhrToArgs(request), event);
  304. };
  305. if (handler.onload) request.onload = function (event) {
  306. return handler.onload(xhrToArgs(request), event);
  307. };
  308. if (handler.onloadend) request.onloadend = function (event) {
  309. return handler.onloadend(xhrToArgs(request), event);
  310. };
  311. if (handler.onloadstart) request.onloadstart = function (event) {
  312. return handler.onloadstart(xhrToArgs(request), event);
  313. };
  314. if (handler.onprogress) request.onprogress = function (event) {
  315. return handler.onprogress(xhrToArgs(request), event);
  316. };
  317. if (handler.ontimeout) request.ontimeout = function (event) {
  318. return handler.ontimeout(xhrToArgs(request), event);
  319. };
  320. if (handler.responseType) request.responseType = handler.responseType;
  321. if (handler.overrideMimeType) request.setRequestHeader("Content-Type", handler.overrideMimeType);
  322. if (handler.data) {
  323. request.send(JSON.stringify(handler.data));
  324. } else {
  325. request.send();
  326. }
  327. return request;
  328. };
  329.  
  330. window.ready = function ready(handler, readyState = "interactive") {
  331. // "loading": 表示文档还在加载中,即处于“正在加载”状态。
  332. // "interactive": 文档已经结束了“正在加载”状态,DOM 元素可以被访问。但是像图像,样式表和框架等资源依然还在加载。
  333. // "complete": 页面所有内容都已被完全加载。
  334. let intervalId = setInterval(function (states = ["loading", "interactive", "complete"]) {
  335. if (states.indexOf(document.readyState.toLowerCase()) >= states.indexOf(readyState.toLowerCase())) {
  336. clearInterval(intervalId);
  337. if (typeof handler === "function") {
  338. handler();
  339. } else {
  340. console.error("Uncaught (in ready) TypeError: " + handler + " is not a function.");
  341. }
  342. }
  343. });
  344. };
  345. })();

QingJ © 2025

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