Javascript 如何使用Tampermonkey重新加载另一个选项卡?
当当前选项卡更改时,我想使用Javascript 如何使用Tampermonkey重新加载另一个选项卡?,javascript,tampermonkey,Javascript,Tampermonkey,当当前选项卡更改时,我想使用Tampermonkey刷新某个选项卡 我是Duolingo的用户,但我对Crown系统的新变化不满意,我也不喜欢他们的“实践”按钮算法 因此,我使用duome.eu网站来选择最弱的进行审查 如本页所示: 此网站上的信息基于用户在 duolingo.com 我点击duome页面上的链接,打开duolingo网站,查看技能。 复习完一项技能后,我想重新加载duome.eu页面,重新计算我的进度 我怎样才能做到这一点 另外,我也愿意接受其他想法,提前感谢:)
Tampermonkey
刷新某个选项卡
我是Duolingo的用户,但我对Crown系统的新变化不满意,我也不喜欢他们的“实践”按钮算法
因此,我使用duome.eu网站来选择最弱的进行审查
如本页所示:此网站上的信息基于用户在 duolingo.com 我点击duome页面上的链接,打开duolingo网站,查看技能。
复习完一项技能后,我想重新加载duome.eu页面,重新计算我的进度 我怎样才能做到这一点 另外,我也愿意接受其他想法,提前感谢:)您可以通过以下方式实现:
// ==UserScript==
// @name _Cross tab, cross domain script communication
// @match *://stackoverflow.com/questions/521295/*
// @match *://stackoverflow.com/posts/521295/timeline
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_setValue
// @grant GM_addValueChangeListener
// ==/UserScript==
const xmssionKey = "Last vote-button click event";
//-- Are we on the "interactive" page/site/domain or the "monitoring" one?
if (location.pathname.includes ("questions") ) {
//-- On the "interactive page/tab...
//-- Hook into the page's vote and favorite buttons:
$(".inner-content").on ("click", ".vote a", zEvent => {
var tmStamp = new Date ().getTime ();
var ctMessage = `Button ${zEvent.target.className} clicked - ${tmStamp}`;
console.log (ctMessage);
//-- Send message to monitoring tab.
GM_setValue (xmssionKey, ctMessage);
} );
}
else {
//-- On the "monitoring" page/tab...
//-- Listen for new message:
GM_addValueChangeListener (
xmssionKey, (keyName, oldValue, newValue, bRmtTrggrd) => {
console.log (`Received new event: ${newValue}`);
//-- User feedback, esp useful with time delay:
document.title = "Reloading...";
/*-- Important:
May need to wait 1 to 300 seconds to allow for
web-app / database / API delays and/or caching.
1222 == 1.2 seconds
*/
setTimeout ( () => {location.reload(); }, 1222);
} );
}
请注意,对于这个特定的示例,两个页面位于同一个域上(只是为了让每个人都更容易运行演示脚本),但是代码/策略对于跨域页面同样有效。更多详细信息?这两个站点是否位于同一来源?@CertainPerformance No,不同的域。但是一个站点是使用另一个站点的信息构建的。我将更新详细信息:)对于无法使其工作的其他人:向消息中添加时间戳或其他更改内容很重要。据您所知,是否有任何方法可以告诉TM跨不同脚本共享存储,或者它需要在不同域上运行相同的脚本?我可以这样做,如果可以避免的话,我宁愿不这样做。