How to run script in specify tab, and not effect the other side tab(Greasemonkey/Tampermonkey)

依然范特西╮ 提交于 2020-08-10 19:17:02

问题


How to run script in specify tab, and not effect the other side tab?

like first tab keep going auto-refresh example.com

as the same time new tab visit example.com(Non auto-refresh)?

#Greasemonkey #Tampermonkey

// ==UserScript==
// @name     Auto-Refresh
// @include  https://www.example.com
// ==/UserScript==

setTimeout(function(){ location.reload(); }, 5000);

回答1:


The question is not clear enough for a definite answer.

User-scripts normally do not have access to TAB data to know which tab they are running on.

Among user-script managers (GreaseMonkey, ViolentMonkey, TamperMonkey & FireMoneky), ATM only TamperMonkey has GM_getTab & GM_getTabs API (Non-standard) to get details about the tab that script runs on. Therefore such solution would only work on TamperMonkey.

Furthermore, the location.reload() also makes it more difficult.

Is that the real code or location.reload() is just an example?



来源:https://stackoverflow.com/questions/62913789/how-to-run-script-in-specify-tab-and-not-effect-the-other-side-tabgreasemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!