Greasy Fork is available in English.

Discussioni » Richieste di creazione

How to make a site/tab think it's still in focus?

§
Pubblicato: 13/04/2021

Does someone have a code i can use so the site/tab thinks it is still in focus while i go to another site/app?

wOxxOmMod
§
Pubblicato: 13/04/2021
Modificato: 13/04/2021

Depending on the site you'll have to spoof the events/properties that it uses. The most common ones are visibilitychange, pagehide, blur so you can start with something like this:

// @run-at document-start
.............
const ael = unsafeWindow.addEventListener;
unsafeWindow.addEventListener = unsafeWindow.document.addEventListener = function(name) {
  if (!/^(visibilitychange|pagehide|blur)$/i.test(name)) {
    return ael.apply(this, arguments);
  }
};

You may need to spoof document.hasFocus() too.

§
Pubblicato: 13/04/2021

sorry, i dont know how to code, what are the parts i need to replace?

Pubblica risposta

Accedi per pubblicare una risposta.