【问题标题】:Tampermonkey run script every 10sTampermonkey 每 10 秒运行一次脚本
【发布时间】:2022-01-11 21:57:35
【问题描述】:

我正在尝试构建一个每 10 秒运行一次并发送 GM_notification 的脚本。但我没有收到任何通知。怎么了?

// ==UserScript==
// @name        _Notification test
// @grant       GM_notification
// @require     http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

setTimeout(function() {

GM_notification ( {title: 'foo', text: '42'} );

}, 1000);

【问题讨论】:

标签: javascript tampermonkey


【解决方案1】:

您需要match url 提供页面的网址,并且对于每个10 秒需要setInterval 而不是setTimeout

// ==UserScript==
// @name        _Notification test
// @match       https://stackoverflow.com/questions/70249774/tampermonkey-run-script-every-10s*
// @grant       GM_notification
// @require     http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==




var intervalId = window.setInterval(function(){
  GM_notification ( {
    title: 'foo', text: '42'
} );
}, 10000);

【讨论】:

  • 我添加了image 参数,但仍然没有显示。如果我添加 // @match stackoverflow.com/questions/70249774* 当我导航到这个页面时会出现通知
  • @rowend 我已经更新了我的答案,现在它正在工作
猜你喜欢
  • 2016-07-24
  • 2013-02-23
  • 2020-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多