Please help me figure it out. I am writing a custom script for Tampermonkey.
Briefly about the script: the script updates the page on the site every 3 minutes, checks for the presence of an object and, if there is one, clicks on it.
Problem: when the tab is inactive (focus on another Google tab or the window is minimized), the script does not work, the setInterval and setTimeout timer stop working and the script does not update or search for anything. How to fix this situation?
// ==UserScript==
// @name User Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author None
// @match https://www.twitch.tv/drops/inventory
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @require https://code.jquery.com/jquery-1.11.0.min.js
// @grant none
/* globals jQuery, $, waitForKeyElements */
// ==/UserScript==
$(window).load(function(){
'use strict';
setTimeout(function(){
function SearchController(){
var i = 0;
var result = '';
$('.dYkLvU').each(function(){
if ($(this).find('button').find('.phMMp').text() == 'Click'){
$(this).find('button').find('.phMMp').trigger('click');
}
});
}
SearchController();
setInterval(function(){
location.reload();
}, 60000);
}, 4000);
});
I know about this thing (https://github.com/turuslan/HackTimer), but for some reason it doesn't work in Tampermonkey.