gpt4 book ai didi

tampermonkey - @grant 指令并通过页面检测用户脚本

转载 作者:行者123 更新时间:2023-12-05 03:24:01 27 4
gpt4 key购买 nike

我的问题有两个方面。首先,有人可以解释一下在 Tampermonkey 中使用 @grant none 的优缺点吗?其次,我应该使用哪些 @grant 值来防止网页检测脚本?

最佳答案

@grant

If @grant is followed by 'none' the sandbox is disabled and the scriptwill run directly at the page context. In this mode no GM_* functionbut the GM_info property will be available.

如果脚本不需要任何 @grant,即脚本是没有任何 GM API 的纯 JavaScript,您可以使用 @grant none。 Tampermonkey 然后将脚本注入(inject) page 上下文(与网页的 JavaScript 相同的上下文)。

通常用户脚本被注入(inject)到 content 上下文中,它与 page 上下文分开。

如果将用户脚本注入(inject)到page 上下文中,那么页面将更容易找到它。同样,如果用户脚本注入(inject)到 content 上下文中,但使用 unsafeWindow 与网页脚本进行交互。

网页不能自动检测用户脚本,但可以检查脚本的结果。

例如……

  • 网页添加广告
  • 用户脚本删除广告
  • 网页检查广告是否还在

网页还可以查找用户脚本可能添加的特定全局变量(如果用户脚本将全局变量添加到 page 上下文中)。

关于tampermonkey - @grant 指令并通过页面检测用户脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72375292/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com