JavaScript setTimeout 在 KRL 应用程序中的 Facebook 上被清除
我正在使用 setTimeout ,它每次运行时都会调用自身以持续检查不同页面的内容,因为每个页面都是通过 ajax 加载的。看来 Facebook JS 正在运行所有可能的 setTimeout 引用,并为每次渲染我的应用程序调用clearTimeout。
有没有办法防止我的 setTimeout 像 Facebook 的 JS 压扁一样无助的小错误?
这是我的代码,这样您就可以看到发生了什么,并根据需要测试您的解决方案:
ruleset a60x542 {
meta {
name "shun-the-facebook-likes"
description <<
shun-the-facebook-likes
>>
author "Mike Grace"
logging off
}
dispatch {
domain "facebook.com"
}
rule find_the_likes {
select when pageview "facebook\.com"
{
emit <|
KOBJ.a60x542.removeLikes = function() {
$K(".uiUfiLike, .like_link, .cmnt_like_link").remove();
var timeout = window.setTimeout(function() {
KOBJ.a60x542.removeLikes();
}, 4000);
console.log(timeout);
} // removeLikes()
KOBJ.a60x542.removeLikes();
|>;
}
}
}
I'm using a setTimeout that calls itself each time it runs to continual check the contents of different pages since each page gets loaded via ajax. It seems that the Facebook JS is running through all the possible setTimeout references and calling clearTimeout for each rendering my app useless.
Is there a way I can prevent my setTimeout from being squashed like a helpless little bug by Facebook's JS?
Here is my code so you can see what is going on and test your solution if you like:
ruleset a60x542 {
meta {
name "shun-the-facebook-likes"
description <<
shun-the-facebook-likes
>>
author "Mike Grace"
logging off
}
dispatch {
domain "facebook.com"
}
rule find_the_likes {
select when pageview "facebook\.com"
{
emit <|
KOBJ.a60x542.removeLikes = function() {
$K(".uiUfiLike, .like_link, .cmnt_like_link").remove();
var timeout = window.setTimeout(function() {
KOBJ.a60x542.removeLikes();
}, 4000);
console.log(timeout);
} // removeLikes()
KOBJ.a60x542.removeLikes();
|>;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定 Facebooks 正在清除您的超时吗?
你的 console.log 工作正常吗?
您可以使用 setInterval 继续执行您的函数。
Are you sure that FAcebooks is clearing your timeouts?
Is your console.log working?
You can use setInterval to comtinuely execute your function.
试试这个,一个对我有用的解决方案:
Try this, a solution which worked for me: