Auto Enable Dark mode for Google

Enable Dark mode automatically

安装此脚本
作者推荐脚本

您可能也喜欢Don't track me Google

安装此脚本
  1. // ==UserScript==
  2. // @name Auto Enable Dark mode for Google
  3. // @namespace https://idunwannagotoschool.com
  4. // @description Enable Dark mode automatically
  5. // @version 2.1.1
  6. // @author John Kai
  7. // @grant none
  8. // @match *://*.google.com/*
  9. // @match *://*.google.ad/*
  10. // @match *://*.google.ae/*
  11. // @match *://*.google.com.af/*
  12. // @match *://*.google.com.ag/*
  13. // @match *://*.google.com.ai/*
  14. // @match *://*.google.al/*
  15. // @match *://*.google.am/*
  16. // @match *://*.google.co.ao/*
  17. // @match *://*.google.com.ar/*
  18. // @match *://*.google.as/*
  19. // @match *://*.google.at/*
  20. // @match *://*.google.com.au/*
  21. // @match *://*.google.az/*
  22. // @match *://*.google.ba/*
  23. // @match *://*.google.com.bd/*
  24. // @match *://*.google.be/*
  25. // @match *://*.google.bf/*
  26. // @match *://*.google.bg/*
  27. // @match *://*.google.com.bh/*
  28. // @match *://*.google.bi/*
  29. // @match *://*.google.bj/*
  30. // @match *://*.google.com.bn/*
  31. // @match *://*.google.com.bo/*
  32. // @match *://*.google.com.br/*
  33. // @match *://*.google.bs/*
  34. // @match *://*.google.bt/*
  35. // @match *://*.google.co.bw/*
  36. // @match *://*.google.by/*
  37. // @match *://*.google.com.bz/*
  38. // @match *://*.google.ca/*
  39. // @match *://*.google.cd/*
  40. // @match *://*.google.cf/*
  41. // @match *://*.google.cg/*
  42. // @match *://*.google.ch/*
  43. // @match *://*.google.ci/*
  44. // @match *://*.google.co.ck/*
  45. // @match *://*.google.cl/*
  46. // @match *://*.google.cm/*
  47. // @match *://*.google.cn/*
  48. // @match *://*.google.com.co/*
  49. // @match *://*.google.co.cr/*
  50. // @match *://*.google.com.cu/*
  51. // @match *://*.google.cv/*
  52. // @match *://*.google.com.cy/*
  53. // @match *://*.google.cz/*
  54. // @match *://*.google.de/*
  55. // @match *://*.google.dj/*
  56. // @match *://*.google.dk/*
  57. // @match *://*.google.dm/*
  58. // @match *://*.google.com.do/*
  59. // @match *://*.google.dz/*
  60. // @match *://*.google.com.ec/*
  61. // @match *://*.google.ee/*
  62. // @match *://*.google.com.eg/*
  63. // @match *://*.google.es/*
  64. // @match *://*.google.com.et/*
  65. // @match *://*.google.fi/*
  66. // @match *://*.google.com.fj/*
  67. // @match *://*.google.fm/*
  68. // @match *://*.google.fr/*
  69. // @match *://*.google.ga/*
  70. // @match *://*.google.ge/*
  71. // @match *://*.google.gg/*
  72. // @match *://*.google.com.gh/*
  73. // @match *://*.google.com.gi/*
  74. // @match *://*.google.gl/*
  75. // @match *://*.google.gm/*
  76. // @match *://*.google.gp/*
  77. // @match *://*.google.gr/*
  78. // @match *://*.google.com.gt/*
  79. // @match *://*.google.gy/*
  80. // @match *://*.google.com.hk/*
  81. // @match *://*.google.hn/*
  82. // @match *://*.google.hr/*
  83. // @match *://*.google.ht/*
  84. // @match *://*.google.hu/*
  85. // @match *://*.google.co.id/*
  86. // @match *://*.google.ie/*
  87. // @match *://*.google.co.il/*
  88. // @match *://*.google.im/*
  89. // @match *://*.google.co.in/*
  90. // @match *://*.google.iq/*
  91. // @match *://*.google.is/*
  92. // @match *://*.google.it/*
  93. // @match *://*.google.je/*
  94. // @match *://*.google.com.jm/*
  95. // @match *://*.google.jo/*
  96. // @match *://*.google.co.jp/*
  97. // @match *://*.google.co.ke/*
  98. // @match *://*.google.com.kh/*
  99. // @match *://*.google.ki/*
  100. // @match *://*.google.kg/*
  101. // @match *://*.google.co.kr/*
  102. // @match *://*.google.com.kw/*
  103. // @match *://*.google.kz/*
  104. // @match *://*.google.la/*
  105. // @match *://*.google.com.lb/*
  106. // @match *://*.google.li/*
  107. // @match *://*.google.lk/*
  108. // @match *://*.google.co.ls/*
  109. // @match *://*.google.lt/*
  110. // @match *://*.google.lu/*
  111. // @match *://*.google.lv/*
  112. // @match *://*.google.com.ly/*
  113. // @match *://*.google.co.ma/*
  114. // @match *://*.google.md/*
  115. // @match *://*.google.me/*
  116. // @match *://*.google.mg/*
  117. // @match *://*.google.mk/*
  118. // @match *://*.google.ml/*
  119. // @match *://*.google.com.mm/*
  120. // @match *://*.google.mn/*
  121. // @match *://*.google.ms/*
  122. // @match *://*.google.com.mt/*
  123. // @match *://*.google.mu/*
  124. // @match *://*.google.mv/*
  125. // @match *://*.google.mw/*
  126. // @match *://*.google.com.mx/*
  127. // @match *://*.google.com.my/*
  128. // @match *://*.google.co.mz/*
  129. // @match *://*.google.com.na/*
  130. // @match *://*.google.com.nf/*
  131. // @match *://*.google.com.ng/*
  132. // @match *://*.google.com.ni/*
  133. // @match *://*.google.ne/*
  134. // @match *://*.google.nl/*
  135. // @match *://*.google.no/*
  136. // @match *://*.google.com.np/*
  137. // @match *://*.google.nr/*
  138. // @match *://*.google.nu/*
  139. // @match *://*.google.co.nz/*
  140. // @match *://*.google.com.om/*
  141. // @match *://*.google.com.pa/*
  142. // @match *://*.google.com.pe/*
  143. // @match *://*.google.com.pg/*
  144. // @match *://*.google.com.ph/*
  145. // @match *://*.google.com.pk/*
  146. // @match *://*.google.pl/*
  147. // @match *://*.google.pn/*
  148. // @match *://*.google.com.pr/*
  149. // @match *://*.google.ps/*
  150. // @match *://*.google.pt/*
  151. // @match *://*.google.com.py/*
  152. // @match *://*.google.com.qa/*
  153. // @match *://*.google.ro/*
  154. // @match *://*.google.ru/*
  155. // @match *://*.google.rw/*
  156. // @match *://*.google.com.sa/*
  157. // @match *://*.google.com.sb/*
  158. // @match *://*.google.sc/*
  159. // @match *://*.google.se/*
  160. // @match *://*.google.com.sg/*
  161. // @match *://*.google.sh/*
  162. // @match *://*.google.si/*
  163. // @match *://*.google.sk/*
  164. // @match *://*.google.com.sl/*
  165. // @match *://*.google.sn/*
  166. // @match *://*.google.so/*
  167. // @match *://*.google.sm/*
  168. // @match *://*.google.sr/*
  169. // @match *://*.google.st/*
  170. // @match *://*.google.com.sv/*
  171. // @match *://*.google.td/*
  172. // @match *://*.google.tg/*
  173. // @match *://*.google.co.th/*
  174. // @match *://*.google.com.tj/*
  175. // @match *://*.google.tk/*
  176. // @match *://*.google.tl/*
  177. // @match *://*.google.tm/*
  178. // @match *://*.google.tn/*
  179. // @match *://*.google.to/*
  180. // @match *://*.google.com.tr/*
  181. // @match *://*.google.tt/*
  182. // @match *://*.google.com.tw/*
  183. // @match *://*.google.co.tz/*
  184. // @match *://*.google.com.ua/*
  185. // @match *://*.google.co.ug/*
  186. // @match *://*.google.co.uk/*
  187. // @match *://*.google.com.uy/*
  188. // @match *://*.google.co.uz/*
  189. // @match *://*.google.com.vc/*
  190. // @match *://*.google.co.ve/*
  191. // @match *://*.google.vg/*
  192. // @match *://*.google.co.vi/*
  193. // @match *://*.google.com.vn/*
  194. // @match *://*.google.vu/*
  195. // @match *://*.google.ws/*
  196. // @match *://*.google.rs/*
  197. // @match *://*.google.co.za/*
  198. // @match *://*.google.co.zm/*
  199. // @match *://*.google.co.zw/*
  200. // @match *://*.google.cat/*
  201. // @match *://*.google.ng/*
  202. // @run-at document-start
  203. // ==/UserScript==
  204.  
  205. let darkModeIsOn = false;
  206. const timer = setInterval(tryDarkMode, 100);
  207.  
  208. function tryDarkMode() {
  209. if (!darkModeIsOn) {
  210. if (document.readyState == 'complete') {
  211. try {
  212. let darkModeButton = document.querySelector('[jsaction*="ok5gFc"]');
  213. if (!darkModeButton) {
  214. let radialButton = document.querySelector('g-radio-button-group div[data-index="1"]');
  215. if (radialButton && radialButton.getAttribute('aria-checked') !== 'true') {
  216. radialButton.click();
  217. darkModeIsOn = true;
  218. }
  219. } else if (darkModeButton.textContent.toLowerCase().includes('dark theme: off')) {
  220. darkModeButton.click();
  221. darkModeIsOn = true;
  222. }
  223. } catch (e) {
  224. console.error(e);
  225. }
  226. }
  227. } else {
  228. clearInterval(timer);
  229. }
  230. }