Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

greasemonkey javascript execute order

My greasemonkey script have two javascript file, How can I make sure my second file doesn't load until the first file completes ?

// ==UserScript==
// @name          hello greasemonkey
// @namespace     http://localhost/test_monkey/
// @description   noob studing 
// @include       http://localhost/test_monkey/test_monkey.html
// ==/UserScript==

loadJsOrCssFile('http://localhost/test_monkey/js/first.js', 'js');`
loadJsOrCssFile('http://localhost/test_monkey/js/second.js', 'js');`

function loadJsOrCssFile(sFileName, sFileType) {
  if (sFileType == 'js') {
    var sFileref = document.createElement('script');
    sFileref.setAttribute('type', 'text/javascript');
    sFileref.setAttribute('src', sFileName);
  }
  else if (sFileType == 'css') {
    var sFileref = document.createElement('link');
    sFileref.setAttribute('rel', 'stylesheet');
    sFileref.setAttribute('type', 'text/css');
    sFileref.setAttribute('href', sFileName);
  }
  if (typeof sFileref != 'undefined')`enter code here`
  document.getElementsByTagName('head') [0].appendChild(sFileref);
}
like image 271
Guan Jyun Chen Avatar asked Jun 20 '26 08:06

Guan Jyun Chen


1 Answers

There is a setting in the TamperMonkey script settings for each script called "run at" and you can set that to "document-end"

I am not as familiar with GreaseMonkey, but maybe there is a similar setting?

like image 54
CodingIsSwell Avatar answered Jun 21 '26 20:06

CodingIsSwell