LoadScript

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

Від 27.05.2015. Дивіться остання версія.

Цей скрипт не слід встановлювати безпосередньо. Це - бібліотека для інших скриптів для включення в мета директиву // @require https://update.greasyfork.org/scripts/10108/54091/LoadScript.js

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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);
  };