loader

动态加载js/css资源

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/477349/1264100/loader.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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