我正在尝试编写一个Tampermonkey脚本,以防止特定的内联脚本标签执行。页面主体看起来像这样。
我试图使用Tampermonkey脚本删除
我该如何防止执行
注意:我想要防止执行的实际
<body>
<!-- the following script tag should be executed-->
<script type="text/javascript">
alert("I'm executed as normal")
</script>
<!-- the following script tag should NOT be executed-->
<script type="text/javascript">
alert("I should not be executed")
</script>
<!-- the following script tag should be executed-->
<script type="text/javascript">
alert("I'm executed as normal, too")
</script>
</body>
我试图使用Tampermonkey脚本删除
script
标签,但是如果我在document-start
或document-body
运行它,则script
标签尚不存在。如果我在document-end
或document-idle
运行它,则我想要删除的script
标签将在我的Tampermonkey脚本执行之前运行。我该如何防止执行
script
标签?
注意:我想要防止执行的实际
script
标签包含window.location = 'redirect-url'
。因此,在这种情况下,防止重新加载也足够了。
版本信息:
- Chromium 65.0.3325.181
- Tampermonkey 4.5
document_start
时将变异观察器附加到document.documentElement
上,并在添加脚本后将其删除。这在 Chrome 85 中对我有效。 - teg_brightly