Search code examples
javascriptgreasemonkeytampermonkey

Overwrite Javascript SetTimeout time but keep the inside function


I'm trying to make a tampermonkey script to reduce the time of a javascript function (SetTimeout) in order to get faster redirect of a page. The page code is this one:

<script type="text/javascript">
    window.setTimeout(function() {
        window.location.replace("http://linkhere.com/R4NDoM1CODEHeRE" + window.location.hash);
    }, 3000);
</script>

I always end up in the same page after being redirected by this one (just like those ADs that forces you to fill reCaptcha and then they transfer you back again to the same page, ask you to wait some seconds and then transfer to another reCaptcha page).

Could someone help me in this task?


Solution

  • It's possible to use a regex to find http://mylinkhere.link and immediately redirect to it (or display the button if you prefer).

    Something like this should work:

    var target = /document\.getElementById\('show'\)\.innerHTML = '<a href="([^"]*)|replace\("([^"]*)" \+ window/.exec(document.documentElement.innerHTML);
    window.location = target[1] || target[2];
    

    Edit: Corrected answer. Changed contents to document.documentElement.innerHTML.

    Edit 2: Corrected answer again.

    Edit 3: Updated the answer so it works on both pages from original question.