Custom-JavaScript-for-Websites-2 icon indicating copy to clipboard operation
Custom-JavaScript-for-Websites-2 copied to clipboard

Options on where to inject script

Open xul8tr opened this issue 6 years ago • 1 comments

Currently, it seems to inject the script at the bottom of the body element. This is causing me an issue currently as I am trying to set a cookie before window.onload.

It would be nice to have a drop-down that allows you to put it in any of these positions:

  1. First script in HEAD tag
  2. Last script in HEAD tag
  3. First script in BODY tag
  4. Last script in BODY tag
  5. Call before defined window's "on load" event. (example see below)
  6. Call after defined window's "on load" event
  7. Call before defined document's "on load" event
  8. Call after defined document's "on load" event
  9. Call before defined document.body's "on load" event
  10. Call after defined document.body's "on load" event

Window before window.onload event example

(I just wrote this quickly I didn't test it but should work or at least shouldn't be hard to get it working)

window.onload_old = window.onload; window.onload = function() {     beforeOnLoad.apply(beforeOnLoad, Array.prototype.slice.call(arguments, 0));     window.onload_old.apply(window.onload_old, Array.prototype.slice.call(arguments, 0)); }

xul8tr avatar Sep 24 '19 06:09 xul8tr

I would very much like to second this. For probably most of my use cases, I'd want to be applying scripts before the page's own javascript is running. Other than that, this extension is great. I've long wanted something like this.

btsheehy avatar Jan 05 '21 17:01 btsheehy