1

whenever I end up on a certain page, which has a certain URL ("A"), i want my browser (Chromium) to wait there 10 seconds (without doing nothing else) and then automatically redirect me to another specific URL ("B")

"A" is a page on a website that sometimes is automatically redirected to "B" in a few fractions of a second (if some conditions are satisfied), but sometimes isn't and it remains stuck there for the rest of its lifetime

I want to force the redirection to happen in every case, and 10 seconds are enough to see if the automatic redirection happened or I have to make it happen in another way

I've found several Chrome extensions that can set up an automatic redirect request, like Requestly or Redirector, but with none of those it's possible to add a "waiting" feature before the redirection

however, Requestly (the most advanced one) allows to load custom CSS or JS code to run it

I don't know absolutely nothing about programming, so what could I write to make the extension do what I want to do?

at least two algorithms could work; a simpler one "detects when I end up on "A", wait 10 s and then redirect to "B" no matter what", or a more sophisticated one "detects when I end up on "A", wait 10 s, see if I'm still on "A" and if yes then redirect to "B" "

thanks in advance for the help!

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
an anon
  • 9
  • 3

1 Answers1

1
setTimeout(
  function() {
    window.location.replace("http://stackoverflow.com");
  }, 10000);

EDIT:

If you want it to work for a specific page, you can wrap it with an if statement.

if (window.location.href === 'https://youtube.com') {
      setTimeout(
        function() {
          window.location.replace("http://stackoverflow.com");
        }, 10000);
}
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
Prajwal
  • 133
  • 1
  • 10
  • The question asks how a browser extension could be written to detect if a user is on one page, and then redirect them to another. – Sean Feb 01 '22 at 14:59
  • Read the question properly before going about downvoting. He said the extension allows custom JS code and wants to know what he could write to make the extension do what he wants. He has no interest in writing a new browser extension. – Prajwal Feb 01 '22 at 15:26
  • They ask for an algorithm that detects which page the user is on. – Sean Feb 01 '22 at 15:58
  • 1
    thanks, the code works because the extension allows me to activate it at a certain condition and the rest is perfect :D – an anon Feb 01 '22 at 20:15