🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

微信读书自动深色模式

根据系统设置自动切换深色模式,深色用的是官方的样式

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         微信读书自动深色模式
// @version      1.0.1
// @description  根据系统设置自动切换深色模式,深色用的是官方的样式
// @namespace    https://weread.qq.com/
// @match        https://weread.qq.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=weread.qq.com
// @author       bowencool
// @license      MIT
// @homepageURL  https://greasyfork.org/scripts/477034
// @supportURL   https://github.com/bowencool/Tampermonkey-Scripts/issues
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  async function toggle(
    isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches
  ) {
    const currentThemeIsWhite =
      document.body.classList.contains("wr_whiteTheme");
    console.log({ isDarkMode, currentThemeIsWhite });
    if (isDarkMode) {
      if (currentThemeIsWhite) {
        document.cookie = "wr_theme=dark; path=/; domain=.weread.qq.com;";
        if (location.pathname.startsWith("/web/reader")) {
          // const button = await waitForElementToExist(
          //   ".readerControls_item.dark"
          // );
          // button.click();
          location.reload();
        } else {
          document.body.classList.remove("wr_whiteTheme");
        }
      }
    } else {
      if (!currentThemeIsWhite) {
        document.cookie = "wr_theme=white; path=/; domain=.weread.qq.com;";
        if (location.pathname.startsWith("/web/reader")) {
          location.reload();
        } else {
          document.body.classList.add("wr_whiteTheme");
        }
      }
    }
  }
  toggle();
  window
    .matchMedia("(prefers-color-scheme: dark)")
    .addEventListener("change", (e) => {
      toggle(e.matches);
    });
})();