remove-debugger

移除 eval 和 Function 中的 debugger 语句

  1. // ==UserScript==
  2. // @name remove-debugger
  3. // @namespace https://github.com/pansong291/
  4. // @version 0.0.2
  5. // @description 移除 eval 和 Function 中的 debugger 语句
  6. // @author paso
  7. // @license Apache-2.0
  8. // @match *://*/*
  9. // @icon
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. ;(function () {
  15. 'use strict'
  16. const oEval = window.eval
  17. const oFunction = window.Function
  18. const handleArgs = (args, last) => {
  19. if (!args?.length) return
  20. const ind = last ? args.length - 1 : 0
  21. if (!args[ind]?.replaceAll) return
  22. args[ind] = args[ind].replaceAll(/\bdebugger\b/g, ';/*debugger*/;')
  23. }
  24. window._original_eval = oEval
  25. window._original_Function = oFunction
  26. window.eval = new Proxy(oEval, {
  27. apply(target, thisArg, argArray) {
  28. handleArgs(argArray, false)
  29. return target.apply(thisArg, argArray)
  30. }
  31. })
  32. window.Function = new Proxy(oFunction, {
  33. apply(target, thisArg, argArray) {
  34. handleArgs(argArray, true)
  35. return target.apply(thisArg, argArray)
  36. },
  37. construct(target, argArray, newTarget) {
  38. handleArgs(argArray, true)
  39. return new target(...argArray)
  40. }
  41. })
  42. oFunction.prototype.constructor = window.Function
  43. }())