javascript - 需要从 HTML 源中复制函数的参数
问题描述
我需要找到部分匹配的字符串(函数名和未知参数),提取参数并使用用户脚本手动启动脚本。问题是,大多数其他脚本都是危险的,所以我将它们全部屏蔽了,这使得该功能只不过是页面中间的文本字符串,以及最重要的 DOM 元素之外。
是的。我没主意了。简而言之,我需要:
找到调用函数的字符串并将其指定为变量的参数;
从该变量参数中提取
有什么帮助吗?
解决方案
你可以 :
- 重写函数;
- 使用
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>
推荐阅读
- flutter - 如何创建单个列表的多个对象
- scala - SortedSet 折叠类型不匹配
- php - GCP Cloud 运行容器服务:[pool www] 无法写入套接字 '/run/php-fpm/www.sock' 的 ACL
- laravel - 如何覆盖 Laravel 中的 logoutOtherDevices() 函数
- c# - 我想获取带有标头的 XML
- java - 如何检查方法的 TypeMirror returnType 是否为枚举
- c# - 如何将字符串数组传递给存储过程?
- swift - 在 Swift 的 ViewController 中显示多个图像
- node.js - docker FILE的理解
- asp.net-mvc - 大家好,我如何将带有 ajax 的列表发布到 MVC