Support @run-at document-idle #2109

Closed
devkev opened this Issue Mar 15, 2015 · 7 comments

Projects

None yet

5 participants

@devkev
devkev commented Mar 15, 2015

Scriptish has a feature where you can specify @run-at document-idle. This runs even later than document-end: from the Scriptish manual this means:

Runs a script some time between document-end and immediately after the window-load (i.e. window.onload()) event fires.

I have several scripts that need to run not only after the DOM has been loaded, but also after early page scripts have been run (to fix up some of the mess they make). In Scriptish this was no problem with document-idle, but having switched back to GM (since Scriptish has fallen into disrepair), I now find that these GM UserScripts no longer work.

The only workaround I have been able to come up with is to wrap my entire UserScript in $(document).ready(function(){ ... }) (using the native jQuery $ from the page, if it has it, otherwise, @requireing jQuery). This works, but feels quite clunky, and nowhere near as easy as just specifying @run-at document-idle.

I saw from this comment in #1103 that the general policy is not to do anything that users could do themselves. I understand this point of view, but it still feels to me like there is a point to making common cases easy for script writers to do - that's the whole success of jQuery, for example. I have no idea how Scriptish actually implements document-idle, but it wouldn't surprise me if it was just syntactic sugar for my jQuery hack above.

In any case, Scriptish can do this, so if GM can as well, then that will help people in porting their scripts when returning to GM. Furthermore, according to this page, Chrome also uses document-idle by default.

@ArkadiuszMichalski

I'm vote to implement this because Scriptish has it and Tampermonkey (for Chrome) by default has something simmilar to works as Stylish (run script after DOMContentLoaded event was dispatched << but we have some delay after dispatched this event) and it will be helpful to faster porting script beetwen different browsers and addons.

By using document-idle at the begining we will get the same behaviour in all browsers, without refactoring code, etc., and we will get easy way to fast change time start for our scripts (just using @run-at with different value).

@devkev
You can use @run-at document-start and listening readystatechange|DOMContentLoaded|load event for document, so you have more options than the default, but its need some refactoring your code.

@arantius arantius added this to the 3.3 milestone Mar 16, 2015
@arantius
Collaborator

Compatibility with other user script engines is the first category of things that breaks that general rule.

@ArkadiuszMichalski

Looks like today Tampermonkey 3.11.4615 implemented document-idle as aption (http://tampermonkey.net/changelog.php?ext=gcal) so now in Chrome we have:

  • document-idle (more delay than default document-end)
  • document-end (must be some delay because Chrome in this aspect is asynchronous)
@arantius arantius modified the milestone: 3.3, 3.4 Jul 10, 2015
@arantius arantius modified the milestone: 3.4, 3.5 Jul 24, 2015
@the8472
Contributor
the8472 commented Aug 24, 2015

I have several scripts that need to run not only after the DOM has been loaded, but also after early page scripts have been run (to fix up some of the mess they make).

have you considered waiting for whatever DOM changes you wish to fix up via mutation observers?

@arantius arantius modified the milestone: 3.6, 3.5 Sep 23, 2015
@arantius arantius added a commit to arantius/greasemonkey that referenced this issue Oct 23, 2015
@arantius arantius Add support for `@run-at document-idle`.
Fixes #2109
759b12f
@arantius arantius closed this in 759b12f Oct 23, 2015
@arantius arantius reopened this Oct 23, 2015
@arantius arantius added a commit to arantius/greasemonkey that referenced this issue Nov 3, 2015
@arantius arantius More comprehensive updateModifiedScripts() for `document-idle`.
Refs #2109
18f06d9
@arantius
Collaborator
arantius commented Nov 3, 2015

Above mentioned issues should be resolved.

@arantius arantius closed this Nov 3, 2015
@seriych
seriych commented Nov 8, 2015

If I'm not mistaken, it must be '_', not '-': 'document_idle'. And the same with _end and _start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment