微信读书自动深色模式

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

  1. // ==UserScript==
  2. // @name 微信读书自动深色模式
  3. // @version 1.0.1
  4. // @description 根据系统设置自动切换深色模式,深色用的是官方的样式
  5. // @namespace https://weread.qq.com/
  6. // @match https://weread.qq.com/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=weread.qq.com
  8. // @author bowencool
  9. // @license MIT
  10. // @homepageURL https://gf.qytechs.cn/scripts/477034
  11. // @supportURL https://github.com/bowencool/Tampermonkey-Scripts/issues
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. "use strict";
  17. async function toggle(
  18. isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches
  19. ) {
  20. const currentThemeIsWhite =
  21. document.body.classList.contains("wr_whiteTheme");
  22. console.log({ isDarkMode, currentThemeIsWhite });
  23. if (isDarkMode) {
  24. if (currentThemeIsWhite) {
  25. document.cookie = "wr_theme=dark; path=/; domain=.weread.qq.com;";
  26. if (location.pathname.startsWith("/web/reader")) {
  27. // const button = await waitForElementToExist(
  28. // ".readerControls_item.dark"
  29. // );
  30. // button.click();
  31. location.reload();
  32. } else {
  33. document.body.classList.remove("wr_whiteTheme");
  34. }
  35. }
  36. } else {
  37. if (!currentThemeIsWhite) {
  38. document.cookie = "wr_theme=white; path=/; domain=.weread.qq.com;";
  39. if (location.pathname.startsWith("/web/reader")) {
  40. location.reload();
  41. } else {
  42. document.body.classList.add("wr_whiteTheme");
  43. }
  44. }
  45. }
  46. }
  47. toggle();
  48. window
  49. .matchMedia("(prefers-color-scheme: dark)")
  50. .addEventListener("change", (e) => {
  51. toggle(e.matches);
  52. });
  53. })();

QingJ © 2025

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