首页 > 解决方案 > 需要从 HTML 源中复制函数的参数

问题描述

我需要找到部分匹配的字符串(函数名和未知参数),提取参数并使用用户脚本手动启动脚本。问题是,大多数其他脚本都是危险的,所以我将它们全部屏蔽了,这使得该功能只不过是页面中间的文本字符串,以及最重要的 DOM 元素之外。
是的。我没主意了。简而言之,我需要:

  1. 找到调用函数的字符串并将其指定为变量的参数;

  2. 从该变量参数中提取

有什么帮助吗?

标签: javascriptuserscripts

解决方案


你可以 :

  • 重写函数;
  • 使用console.trace()
  • 或者像这样显示函数的代码源:functionName.toString()

const ouput = document.getElementById("output");

function littleBrother(arg1, arg2, arg3) {
   console.log("I'm good.", arg1, arg2, arg3);
}

(function overWriteFunction(original) {
  ouput.value = original.toString();
  
  littleBrother = function () {
    console.log("My little brother will say something, with this args :", arguments);
    console.trace(); // Watch your console.
    original.apply(window, arguments);
  };
})(littleBrother);


littleBrother(12, 5, 6);
<textarea id="output" rows="4" cols="50"></textarea>


推荐阅读