remove-debugger

移除 eval 和 Function 中的 debugger 语句

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name            remove-debugger
// @namespace       https://github.com/pansong291/
// @version         0.0.2
// @description     移除 eval 和 Function 中的 debugger 语句
// @author          paso
// @license         Apache-2.0
// @match           *://*/*
// @icon
// @grant           none
// @run-at          document-start
// ==/UserScript==

;(function () {
  'use strict'
  const oEval = window.eval
  const oFunction = window.Function
  const handleArgs = (args, last) => {
    if (!args?.length) return
    const ind = last ? args.length - 1 : 0
    if (!args[ind]?.replaceAll) return
    args[ind] = args[ind].replaceAll(/\bdebugger\b/g, ';/*debugger*/;')
  }
  window._original_eval = oEval
  window._original_Function = oFunction
  window.eval = new Proxy(oEval, {
    apply(target, thisArg, argArray) {
      handleArgs(argArray, false)
      return target.apply(thisArg, argArray)
    }
  })
  window.Function = new Proxy(oFunction, {
    apply(target, thisArg, argArray) {
      handleArgs(argArray, true)
      return target.apply(thisArg, argArray)
    },
    construct(target, argArray, newTarget) {
      handleArgs(argArray, true)
      return new target(...argArray)
    }
  })
  oFunction.prototype.constructor = window.Function
}())