简体   繁体   English

取消覆盖 JavaScript function

[英]Un-overwrite a JavaScript function

I made UserScripts, and am now stuck.我制作了 UserScripts,现在卡住了。

Inside of my HTML there is a script tag, and inside the script tag there is the following:在我的 HTML 里面有一个 script 标签,在 script 标签里面有以下内容:

<script>
   setTimeout = function(){}
</script>

There is no way to use the function, its useless. function没办法用,没用。

How can I solve this?我该如何解决这个问题?

I was thinking using a way to set the function like main = setTimeout() and I can reset it after the script is loaded.我正在考虑使用一种方法来设置 function,例如main = setTimeout()并且我可以在加载脚本后重置它。 Back to like setTimeout = main .回到喜欢setTimeout = main

I am also trying to stay (mostly) undetected unlike running all of the code in a different environment like an iframe. I know you can just use setInterval and then break the loop, but this is just an example.我也试图保持(大部分)未被发现,这与在 iframe 等不同环境中运行所有代码不同。我知道你可以只使用setInterval然后中断循环,但这只是一个例子。

Run your userscript before the page has a chance to overwrite it.在页面有机会覆盖它之前运行您的用户脚本。 Use // @run-at document-start in the metadata block (combined with instant script injection in the Advanced section of Tampermonkey's config), and then you could do, in your userscript:在元数据块中使用// @run-at document-start (结合 Tampermonkey 配置的高级部分中的即时脚本注入),然后您可以在您的用户脚本中执行以下操作:

const origSetTimeout = window.setTimeout;
// proceed with your script, referencing origSetTimeout

which will continue to work even after the page loads and has overwritten the original setTimeout .即使在页面加载并覆盖了原始setTimeout之后,它仍将继续工作。 (While you could reassign window.setTimeout back to the original one later, that would be detectable - if that's really a concern.) (虽然您可以稍后将window.setTimeout重新分配回原来的那个,但这是可以检测到的 - 如果这真的是一个问题。)

The variables declared in the userscript, even at the top level, will not leak out into the page scope, so don't worry about origSetTimeout being exposed - though other actions done in the userscript could be detected.在用户脚本中声明的变量,即使在顶层,也不会泄漏到页面 scope 中,因此不必担心origSetTimeout被暴露——尽管可以检测到在用户脚本中完成的其他操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM