Greasemonkey:停止嵌入式 JS 运行
页面的 html 中包含以下内容:
<script type="text/javascript">
// some code
</script>
我的greasemonkey 脚本需要阻止该脚本运行。我该怎么做?
更新:我知道在一般情况下这是不可能的。但是,在我的具体情况下,我可能有漏洞?
<script type="text/javascript">
if (!window.devicePixelRatio) {
// some code that I -don't- want to be run, regardless of the browser
}
</script>
有什么方法可以在嵌入脚本运行之前定义 window.devicePixelRatio
吗?
A page has the following in the html:
<script type="text/javascript">
// some code
</script>
My greasemonkey script needs to prevent that script from running. How can I do this?
Update: I understand that in the general case this is impossible. However, in my specific case, I may have a loophole?
<script type="text/javascript">
if (!window.devicePixelRatio) {
// some code that I -don't- want to be run, regardless of the browser
}
</script>
Is there some way I can define window.devicePixelRatio
before the embedded script runs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在可以通过
@run-at document-start
和 Firefox 的beforescriptexecute
。仅在 FF24 中测试。beforescriptexecute
在 2016 年被 HTML 5 拒绝,并且< a href="https://www.chromestatus.com/feature/5711871906676736" rel="nofollow noreferrer">Chrome 不太可能实现它。它不会针对其他脚本插入的
节点运行。
This is now possible with
@run-at document-start
and Firefox'sbeforescriptexecute
. Tested only in FF24.beforescriptexecute
was rejected for HTML 5 in 2016, and Chrome is unlikely to implement it.It does not run for
<script>
nodes inserted by other scripts.关于:
现在有了。就像这样:
一般情况:
从 Firefox 版本 4 开始,现在只能在 Firefox 上实现这一点。使用
checkForBadJavascripts
实用程序来利用beforescriptexecute.像这样:
这会阻止第一个内联脚本,其中包含
window.devicePixelRatio
,完全。如果您想有选择地修改该脚本的部分内容,请参阅此答案和/或这个答案。Re:
There is now. Like so:
In the general case:
Since Firefox version 4, this is now possible on Firefox only. Use the
checkForBadJavascripts
utility to leverage the power ofbeforescriptexecute
. Like so:This blocks the first inline script, that contains
window.devicePixelRatio
, entirely. If you want to selective modify parts of that script, see this answer and/or this answer.用户脚本在页面加载后运行,因此您无法这样做。
除非,代码使用“onload”事件。
User scripts run after the page is loaded, so you aren't able to.
Unless, the code uses the "onload" event.
另一种选择是使用 Privoxy 而不是 GreaseMonkey。您只需使用 Privoxy 作为代理(在本地主机上)并搜索/替换您不喜欢的字符串。
Another option is to use Privoxy instead of GreaseMonkey. You just use Privoxy as your proxy (on localhost) and search/replace the strings you don't like.