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