Useful functions for myself
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/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);
}