Greasemonkey JavaScript执行顺序

3
我的Greasemonkey脚本有两个JavaScript文件,我该如何确保第二个文件在第一个文件完成之前不会加载?
// ==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);
}

sFileref.async = false; - YOU
1个回答

1
TamperMonkey脚本设置中有一个名为“运行于(run at)”的选项,您可以将其设置为“文档结束(document-end)”。
我对GreaseMonkey不是很熟悉,但也许有类似的设置?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接