Greasy Fork

来自缓存

Greasy Fork is available in English.

Ko-fi auto dark mode

Ko-fi recently added a native dark mode that has to be manually switched on. This script makes it so that it will automatically follow your OS preference.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Ko-fi auto dark mode
// @namespace    https://phasmidasmr.com
// @version      1.0
// @description  Ko-fi recently added a native dark mode that has to be manually switched on. This script makes it so that it will automatically follow your OS preference.
// @author       Phasmid ASMR
// @match        https://ko-fi.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ko-fi.com
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const toggleDarkTheme = () => {
    const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
    const currentTheme = document.documentElement.getAttribute("data-theme");

    if ((prefersDarkScheme && currentTheme !== "dark") || (!prefersDarkScheme && currentTheme !== "light")) {
      const newTheme = prefersDarkScheme ? "dark" : "light";
      document.documentElement.setAttribute("data-theme", newTheme);
      document.querySelector('#darkThemeToggle').click();
    }
  };

  // Call toggleDarkTheme on load
  toggleDarkTheme();

  // Listen for changes in the user's color scheme preference and call toggleDarkTheme
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", toggleDarkTheme);

})();