Greasy Fork

Greasy Fork is available in English.

style-shims

Shims for GM_addStyle and GM.addStyle.

当前为 2023-12-26 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/483122/1301657/style-shims.js

// ==UserScript==
// @name               style-shims
// @description        Shims for GM_addStyle and GM.addStyle.
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.0
// @license            MIT
// ==/UserScript==

var GM = GM ?? {};

var GM_addStyle = GM_addStyle ?? function GM_addStyle(css)
{
    const style = document.createElement("style");
    style.setAttribute("type", "text/css");
    style.textContent = css;

    const target = document.head ?? document.documentElement;
    return target.appendChild(style);
}

GM.addStyle = GM.addStyle ?? async function addStyle(css)
{
    return GM_addStyle(css);
}