Anti-Disable-Devtool

Intercepts hooks and scripts.

目前为 2024-01-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Anti-Disable-Devtool
  3. // @description Intercepts hooks and scripts.
  4. // @author Snipcola
  5. // @namespace https://snipcola.com
  6. // @license MIT
  7. // @match *://*/*
  8. // @version 1.0
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. const blacklistedHooks = ["contextmenu"];
  13. const blacklistedScripts = ["cdn.jsdelivr.net/npm/disable-devtool"];
  14.  
  15. const name = "Anti-Disable-Devtool";
  16. const originalAddEventListener = document.addEventListener;
  17.  
  18. document.addEventListener = function (type, listener, options) {
  19. if (blacklistedHooks.includes(type)) console.error(`[${name}] Intercepted event from being hooked:`, { type, listener });
  20. else originalAddEventListener.call(document, type, listener, options);
  21. };
  22.  
  23. new MutationObserver((mutations) => {
  24. mutations.forEach(({ addedNodes }) => {
  25. addedNodes.forEach((node) => {
  26. if (node.nodeType === 1 && node.tagName === "SCRIPT" && blacklistedScripts.map((s) => node.src?.includes(s)).includes(true)) {
  27. node.type = "javascript/intercepted";
  28. node.remove();
  29. console.error(`[${name}] Intercepted script from being executed:`, { node, source: node.src });
  30. }
  31. });
  32. });
  33. }).observe(document.documentElement, {
  34. childList: true,
  35. subtree: true
  36. });