style-shims

Shims for GM_addStyle and GM.addStyle.

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/483122/1303118/style-shims.js

  1. // ==UserScript==
  2. // @name style-shims
  3. // @description Shims for GM_addStyle and GM.addStyle.
  4. // @author Jason Kwok
  5. // @namespace https://jasonhk.dev/
  6. // @version 1.0.2
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10. let GM_addStyle = function GM_addStyle(css)
  11. {
  12. const style = document.createElement("style");
  13. style.setAttribute("type", "text/css");
  14. style.textContent = css;
  15.  
  16. const target = document.head ?? document.documentElement;
  17. return target.appendChild(style);
  18. }
  19.  
  20. GM.addStyle = async function addStyle(css)
  21. {
  22. return GM_addStyle(css);
  23. }