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: 7
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

Post Reply

Return to “Development”

Who is online

Users browsing this forum: No registered users and 1 guest