loader

动态加载js/css资源

Från och med 2023-10-13. Se den senaste versionen.

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greatest.deepsurf.us/scripts/477349/1264100/loader.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.

(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!)

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