vPlus

让 v2ex 跟随系统的深色/浅色模式

  1. // ==UserScript==
  2. // @name vPlus
  3. // @namespace https://greasyfork.org/en/users/190451-leo-aee
  4. // @version 0.1.4
  5. // @description 让 v2ex 跟随系统的深色/浅色模式
  6. // @author Leoaee
  7. // @icon https://cdn.jsdelivr.net/gh/mopig/oss@master/uPic/202005/v_logo.png
  8. // @include https://*.v2ex.com/*
  9. // @include https://v2ex.com/*
  10. // @match <$URL$>
  11. // @grant none
  12. // @license LGPLv3
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Your code here...
  19. function detectColorScheme(){
  20. var ret = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
  21. return ret;
  22. }
  23. var curScheme = detectColorScheme()
  24. var curColor = document.querySelector('.light-toggle > img').alt.toLowerCase()
  25. if(curScheme !== curColor) {
  26. document.querySelector('.light-toggle').click()
  27. }
  28. })();