style-shims

Shims for GM_addStyle and GM.addStyle.

目前為 2023-12-28 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/483122/1302814/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.1
// @license            MIT
// ==/UserScript==

var GM = GM ?? this.GM ?? {};

var GM_addStyle = GM_addStyle ?? this.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);
}