Bilibili主題色自動切換

讓Bilibili的主題與系統主題保持同步。

// ==UserScript==
// @name         BiliDynTheme
// @name:zh-CN Bilibili主题色自动切换
// @name:zh-TW Bilibili主題色自動切換
// @namespace    http://tampermonkey.net/
// @version      2025-11-10
// @description  Keeps Bilibili’s theme in sync with your OS theme.
// @description:zh-CN 让Bilibili的主题与系统主题保持同步。
// @description:zh-TW 讓Bilibili的主題與系統主題保持同步。
// @author       Ethan Dong
// @match        https://*.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?sz=256&domain=https://www.bilibili.com/
// @grant        none
// @run-at       document-end
// @license MIT
// ==/UserScript==

(function() {
    const themeMedia = window.matchMedia('(prefers-color-scheme: dark)');
    function toggleTheme(e){
        console.log("Triggered")
        const bg = document.querySelector("#app > div.bg");
        if(e.matches){
            document.documentElement.classList.add("bili_dark");
            bg.style.backgroundImage='url("//i0.hdslb.com/bfs/static/stone-free/dyn-home/assets/[email protected]")'
            document.cookie = "theme_style=dark; path=/; domain=.bilibili.com"
            console.log("dark cookie set")

        }else{
            document.documentElement.classList.remove("bili_dark");
            bg.style.backgroundImage='url("//i0.hdslb.com/bfs/static/stone-free/dyn-home/assets/[email protected]")'
            document.cookie = "theme_style=light; path=/; domain=.bilibili.com"
            console.log("light cookie set")

        }

    }
    themeMedia.addEventListener("change",toggleTheme)
    toggleTheme(themeMedia)

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址