run X seconds after document-end?

Post Reply
Posts: 1
Joined: 06.07.17 21:41:18

run X seconds after document-end?

Post by grimblefritz » 06.07.17 21:51:23

I have a site that does at least three page reloads before it gets to the full page render. Even when set to run at document-end, the user script fires several seconds too soon. In fact, using document-end causes the site to hang most of the time.

If I wait for the page to load and paste the script into the console, it works flawlessly.

Being pretty much a novice with javascript and jquery, and an absolute noob with TM -- is there a way to combine document-end with a time delay as well? I can't track down any element that's changed on the page during this final couple of seconds, so I can't use that as a trigger. However, it seems there are some scripts that must still be running and take those seconds to complete.

Ideas anyone?

Posts: 21
Joined: 29.06.17 18:20:11

Re: run X seconds after document-end?

Post by janb » 11.07.17 17:22:18

Something like this?

Code: Select all

// ==UserScript==
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    var waitFn = function () {
        setTimeout(initFn, 3000); //wait 3 secs before executing initFn
    var initFn = function () {
        // all other code
    waitFn(); //start waitFn

Posts: 5
Joined: 15.09.17 13:40:53

Re: run X seconds after document-end?

Post by ricardophp29 » 15.09.17 13:58:58

I did something like this

Code: Select all

$(document).ready(function() {
    }, 2000);
All my methods are in 'startApplication' method, so all executes after 2 seconds documenty ready, i did it because the page that the script executes has some 'Ajax' when page Load and i have wait them complete.

Post Reply