zhangtai
2/8/2018 - 3:00 AM

Loading jQuery

const extLibs = {
    load: function(url, type, name, callback) {
        if (type == 'js') {
            let script = document.createElement('script')
            script.type = 'text/javascript'
            let loaded
            script.src = url
            if (callback) {
                script.onreadystatechange = script.onload = function() {
                  if (!loaded) {
                    callback();
                  }
                  loaded = true;
                };
              }
            document.getElementsByTagName('head')[0].appendChild(script)
        } else if (type == 'css') {
            let link = document.createElement("link")
            link.rel = "stylesheet"
            link.type = "text/css"
            let loaded
            link.href = url
            if (callback) {
                link.onreadystatechange = link.onload = function() {
                  if (!loaded) {
                    callback();
                  }
                  loaded = true;
                };
              }
            document.getElementsByTagName('head')[0].appendChild(link)
        }
    }
}

$('head').append('<link rel="stylesheet" href="https://abc.css">')
$.getScript( "ajax/test.js", function() {  console.log( "loaded" )})
// ==UserScript==
// @name         Tampermonkey Teamplate
// @namespace    https://zhangt.ai
// @version      0.1
// @description  Tampermonkey Teamplate
// @author       Zhang Tai
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @match        <$URL$>
// ==/UserScript==

(function() {
    console.log("Tampermonkey Teamplate");
})();
var script = document.createElement("script");
  script.setAttribute("src", "//code.jquery.com/jquery-3.3.1.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    document.body.appendChild(script);
  }, false);
document.body.appendChild(script);