LoadScript

一个用于按顺序加载外部js的脚本的库

Mint 2015.05.27.. Lásd a legutóbbi verzió

Ezt a szkriptet nem ajánlott közvetlenül telepíteni. Ez egy könyvtár más szkriptek számára, amik tartalmazzák a // @require https://update.greasyfork.org/scripts/10108/54091/LoadScript.js hivatkozást.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        LoadScript
// @namespace   brambles
// @version     1.1
// @grant       none
// ==/UserScript==
  var LoadScript = function LoadScript(urls, callback) {
    var _loadScript = arguments.callee;
    var head = document.head;
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.async = 'true';
    script.className = 'loadscript';
    script.setAttribute('charset', 'utf-8');

    if (typeof urls === 'string') {
      var urls = [
        urls
      ];
    }
    if (!Array.isArray(urls)) {
      throw 'type error';
    }
    if (urls.length > 1) {
      script.onload = script.onerror = function () {
        _loadScript(urls.slice(1), callback);
      };
    } 
    else {
      script.onload = script.onerror = callback;
    }
    script.src = urls[0];
    head.insertBefore(script, head.firstChild);
  };