Home > other >  Tampermonkey run script every 10s
Tampermonkey run script every 10s

Time:12-07

I'm trying to build a script that runs every 10seconds and sends a GM_notification. But I dont receive any notification. What's wrong?

// ==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);

CodePudding user response:

you need match url give url of page and for every 10 sec need setInterval not 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);
  • Related