style-shims

Shims for GM_addStyle and GM.addStyle.

目前为 2023-12-28 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果你需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/483122/1302814/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.1
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10. var GM = GM ?? this.GM ?? {};
  11.  
  12. var GM_addStyle = GM_addStyle ?? this.GM_addStyle ?? function GM_addStyle(css)
  13. {
  14. const style = document.createElement("style");
  15. style.setAttribute("type", "text/css");
  16. style.textContent = css;
  17.  
  18. const target = document.head ?? document.documentElement;
  19. return target.appendChild(style);
  20. }
  21.  
  22. GM.addStyle = GM.addStyle ?? async function addStyle(css)
  23. {
  24. return GM_addStyle(css);
  25. }