如何使用 Tampermonkey 重新加载另一个标签页?
How to Use Tampermonkey to reload another tab?
我想在当前标签改变时刷新某个标签,使用Tampermonkey
。
我是 Duolingo 的用户,但我对他们对皇冠系统的新变化不满意,我不喜欢他们的算法 'Practice' 按钮。
所以,我使用网站duome.eu来选择最弱的进行审查。
在本页点赞:
https://duome.eu/example/progress
本网站上的信息是基于用户在
duolingo.com。
我点击duome页面的link打开duolingo网站查看技能
完成一项技能的复习后,我希望duome.eu的页面重新加载以重新计算我的进度。
我怎样才能做到这一点?
此外,我对其他想法持开放态度,在此先感谢:)
您可以通过以下方式完成此操作:
- 在两个域.
上将您的 Tampermonkey 脚本设置为 运行
- 脚本实例之间的通信 使用
GM_setValue()
Doc and GM_addValueChangeListener()
Doc and, optionally, GM_getValue()
Doc。
例如,您希望在每次单击投票按钮或最喜欢的明星时监控 this random question, and reload its timeline page。
这个 完整的工作 Tampermonkey 脚本 可以做到这一点:
// ==UserScript==
// @name _Cross tab, cross domain script communication
// @match *://whosebug.com/questions/521295/*
// @match *://whosebug.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);
} );
}
- 安装脚本。
- 打开the timeline page。
- 打开the question page。
- 单击其中一个投票按钮或最喜欢的明星。
- 您将看到时间线页面自动重新加载。
请注意,对于这个特定示例,两个页面都在同一个域中(只是为了让每个人更容易 运行 演示脚本),但是 code/strategy同样适用于跨域页面。
我想在当前标签改变时刷新某个标签,使用Tampermonkey
。
我是 Duolingo 的用户,但我对他们对皇冠系统的新变化不满意,我不喜欢他们的算法 'Practice' 按钮。
所以,我使用网站duome.eu来选择最弱的进行审查。
在本页点赞:
https://duome.eu/example/progress
本网站上的信息是基于用户在 duolingo.com。
我点击duome页面的link打开duolingo网站查看技能
完成一项技能的复习后,我希望duome.eu的页面重新加载以重新计算我的进度。
我怎样才能做到这一点?
此外,我对其他想法持开放态度,在此先感谢:)
您可以通过以下方式完成此操作:
- 在两个域. 上将您的 Tampermonkey 脚本设置为 运行
- 脚本实例之间的通信 使用
GM_setValue()
Doc andGM_addValueChangeListener()
Doc and, optionally,GM_getValue()
Doc。
例如,您希望在每次单击投票按钮或最喜欢的明星时监控 this random question, and reload its timeline page。
这个 完整的工作 Tampermonkey 脚本 可以做到这一点:
// ==UserScript==
// @name _Cross tab, cross domain script communication
// @match *://whosebug.com/questions/521295/*
// @match *://whosebug.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);
} );
}
- 安装脚本。
- 打开the timeline page。
- 打开the question page。
- 单击其中一个投票按钮或最喜欢的明星。
- 您将看到时间线页面自动重新加载。
请注意,对于这个特定示例,两个页面都在同一个域中(只是为了让每个人更容易 运行 演示脚本),但是 code/strategy同样适用于跨域页面。