由禅姌 发表于 2022-4-6 21:10:37

李恒道 发表于 2022-4-6 21:00
这样的话实现就看自己怎么设计了
哪种方法都可以的
setinterval劫持要做来源过滤


嘿嘿嘿,劫持嘿嘿嘿

cxxjackie 发表于 2022-4-6 22:07:33

试了一下没有发现问题,有没有可能是你其他代码或者脚本冲突造成的?你自己排查一下看看,另外这个页面的定时器id有全局引用,这样更简单一点:
clearInterval(unsafeWindow.focusautoshow);

dahua1 发表于 2022-4-7 11:00:10

本帖最后由 dahua1 于 2022-4-7 11:05 编辑

cxxjackie 发表于 2022-4-6 22:07
试了一下没有发现问题,有没有可能是你其他代码或者脚本冲突造成的?你自己排查一下看看,另外这个页面的定 ...

// ==UserScript==
// @name         测试
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description222222
// @author       You
// @match      http://*/*
// @match      https://*/*
// @run-at       document-start
// @grant      unsafeWindow
// @grant      GM_addStyle
// @grant      GM_deleteValue
// @grant      GM_listValues
// @grant      GM_addValueChangeListener
// @grant      GM_removeValueChangeListener
// @grant      GM_setValue
// @grant      GM_getValue
// @grant      GM_log
// @grant      GM_getResourceText
// @grant      GM_getResourceURL
// @grant      GM_registerMenuCommand
// @grant      GM_unregisterMenuCommand
// @grant      GM_openInTab
// @grant      GM_xmlhttpRequest
// @grant      GM_download
// @grant      GM_getTab
// @grant      GM_saveTab
// @grant      GM_getTabs
// @grant      GM_notification
// @grant      GM_setClipboard
// @grant      GM_info
// @nocompat   Chrome
// @run-at document-idle
// ==/UserScript==

var id = setInterval(function() {}, 0);
while (id--) clearInterval(id);

setTimeout(function () {
    document.querySelector("head").innerHTML = ""
    document.querySelector("body").innerHTML = ""
},3000)

setTimeout(function () {
    var id = setInterval(function() {}, 0);
    while (id--) clearInterval(id);
},5000)




我的意思是用类似这样的代码,先清除掉页面,在油猴里面关闭不掉页面原本的定时器,在控制台每一秒都会出一个错误,测试网站是这个http://bbs.runbible.cn/forum.php

cxxjackie 发表于 2022-4-7 11:43:45

dahua1 发表于 2022-4-7 11:00
// ==UserScript==
// @name         测试
// @namespace    http://tampermonkey.net/


我用油猴试过了没问题啊,估计是你有什么别的插件或脚本对clearInterval做了手脚,在控制台打印clearInterval函数看看。

dahua1 发表于 2022-4-7 12:24:16

cxxjackie 发表于 2022-4-7 11:43
我用油猴试过了没问题啊,估计是你有什么别的插件或脚本对clearInterval做了手脚,在控制台打印clearInte ...

!(data/attachment/forum/202204/07/122228x8ti6u696ltlhzlu.png)


common.js?QES:1 Uncaught TypeError: Cannot read properties of null (reading 'innerHTML')
    at showfocus (common.js?QES:1:52172)
    at <anonymous>:1:1
showfocus        @        common.js?QES:1
(匿名)        @        VM108:1



全部都是这个错误,,1秒一个,谷歌和火狐浏览器都试了,不行的呢,只运行了这一个脚本

脚本体验师001 发表于 2022-4-7 13:09:15

cxxjackie 发表于 2022-4-7 13:02
我知道了,我换了一个版本的油猴也出现了这个问题,是因为油猴在@grant unsafeWindow的情况下,提供的set ...

是的
如果不动计时器的话 unsafeWindow.showfocus = function () {};
就不知道楼主真正的需求是什么

dahua1 发表于 2022-4-7 13:16:57

cxxjackie 发表于 2022-4-7 13:02
我知道了,我换了一个版本的油猴也出现了这个问题,是因为油猴在@grant unsafeWindow的情况下,提供的set ...

setTimeout(function () {
    var id = unsafeWindow.setInterval(function() {}, 0);
    while (id--) unsafeWindow.clearInterval(id);
},5000)

改成这样真行了...
页: 1 [2]
查看完整版本: 在油猴中如何停止页面上的所有定时器