loader

动态加载js/css资源

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/477349/1264100/loader.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!)

var loader = {
	baseUrl: "",
	css(path) {
		if (!path) {
			throw new Error("loader css argument " + path + " is required !")
		}
		var arr = typeof path == "string" ? [path] : path,
			head = document.getElementsByTagName("head")[0]
		for (var i = 0; i < arr.length; i++) {
			path = this.baseUrl + arr[i]
			if (!path) continue
			var link = document.createElement("link")
			link.rel = "stylesheet"
			link.type = "text/css"
			link.href = path
			head.appendChild(link)
		}
	},
	js(path, charset) {
		if (!path) {
			throw new Error('loader js argument "path" is required !')
		}
		var arr = typeof path == "string" ? [path] : path,
			head = document.getElementsByTagName("head")[0]
		for (var i = 0; i < arr.length; i++) {
			path = this.baseUrl + arr[i]
			if (!path) continue
			var script = document.createElement("script")
			script.type = "text/javascript"
			script.src = path
			if (charset) {
				script.charset = charset
			}
			head.appendChild(script)
		}
	},
}