LoadScript

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

Verze ze dne 27. 05. 2015. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/10108/54091/LoadScript.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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