Basic Functions (For userscripts)

Useful functions for myself

目前为 2023-01-30 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://updategreasyfork.deno.dev/scripts/456034/1143733/Basic%20Functions%20%28For%20userscripts%29.js

// Append a style text to document(<head>) with a <style> element
	// arguments: css | parentElement, css | parentElement, css, attributes
    function addStyle() {
    	// Get arguments
    	const [parentElement, css, attributes] = parseArgs([...arguments], [
    		[2],
    		[1,2],
    		[1,2,3]
    	], [document.head, '', {}]);

    	// Make <style>
		const style = $CrE("style");
		style.textContent = css;
		for (const [name, val] of Object.entries(attributes)) {
			style.setAttribute(name, val);
		}

		// Append to parentElement
        parentElement.appendChild(style);
    }