Greasy Fork is available in English.

Darkmode User

Darkmode for the websites.

  1. // ==UserScript==
  2. //
  3. // @name Darkmode User
  4. // @version 1.8.1
  5. // @namespace https://github.com/Purfview/Darkmode-User
  6. // @description Darkmode for the websites.
  7. // @icon https://i.imgur.com/ZftAaI6.png
  8. // @license MIT
  9. //
  10. // @homepage https://github.com/Purfview/Darkmode-User
  11. // @supportURL https://github.com/Purfview/Darkmode-User/issues
  12. //
  13. // @require https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js
  14. // @require https://greasyfork.org/scripts/403996-exev/code/ExEv.js?version=808391
  15. //
  16. // @include https://karagarga.in/*
  17. // @include https://secret-cinema.pw/*
  18. // @include https://forum.doom9.org/*
  19. // @include https://greasyfork.org/*
  20. // @include https://www.cinematik.net/*
  21. //
  22. // @run-at document-start
  23. // @noframes
  24. //
  25. // ==/UserScript==
  26. //
  27. /*========================= Version History ==================================
  28.  
  29. 1.0 - First public release, only one site added.
  30.  
  31. 1.1 - Added SC site.
  32. - Added basic func for the "unknown" sites at @include.
  33. - Sites' specific code was split to separate functions.
  34. - Much faster switching to darkmode (no waiting for external images/resources).
  35. - Return original background in white mode.
  36.  
  37. 1.2 - Fixed few SC icons.
  38.  
  39. 1.3 - Added Doom9 site.
  40.  
  41. 1.4 - Added Greasyfork site. Some tweaks for SC and Doom9.
  42.  
  43. 1.5 - Script wasn't working with Tampermonkey from v1.1. Fixed!
  44.  
  45. 1.6 - Added Tik site.
  46.  
  47. 1.7 - New feature: Seamless transitions to darkmode.
  48.  
  49. 1.7.1 - Less contrast on the toggle button.
  50.  
  51. 1.7.2 - Fixed KG.
  52.  
  53. 1.7.3 - Fixed menus on SC and Greasyfork.
  54.  
  55. 1.7.4 - KG tweaks.
  56.  
  57. 1.7.5 - KG tweaks.
  58.  
  59. 1.7.6 - SC tweak.
  60.  
  61. 1.8.0 - Removed Tik.
  62. Possible fix for "sometimes script not loadding".
  63.  
  64. 1.8.1 - Improved "1.8.0" fix
  65.  
  66. ==============================================================================*/
  67.  
  68.  
  69. //==============================================================================
  70. // Sites' specific funcs.
  71. //==============================================================================
  72.  
  73. function siteKG() {
  74. const urlPath = window.location.pathname;
  75. if (urlPath == '/browse.php' ||
  76. urlPath == '/current.php' ||
  77. urlPath == '/history.php' ||
  78. urlPath == '/friends.php' ||
  79. urlPath == '/bookmarks.php' ||
  80. urlPath == '/reqdetails.php' ||
  81. urlPath == '/mytorrents.php' ) {
  82. addGlobalStyles('img {mix-blend-mode: screen}');
  83. addGlobalStyles('a div img {mix-blend-mode: normal}');
  84. addGlobalStyles('table .clear {isolation: isolate}');
  85. addGlobalStyles('table[cellpadding="10"][bgcolor="red"] {mix-blend-mode: difference}');
  86. addGlobalStyles('table[width="660"][cellpadding="10"] tbody tr[style="background-color: #008000; color: #fff;"] {mix-blend-mode: difference}');
  87. addGlobalStyles('body>table>tbody>tr>td.outer>span {mix-blend-mode: difference}');
  88. addGlobalStyles('body>table>tbody>tr>td.embedded {mix-blend-mode: screen}');
  89. } else if (urlPath == '/userdetails.php') {
  90. addGlobalStyles('table[width="660"][cellpadding="10"] tbody tr[style="background-color: #008000; color: #fff;"] {mix-blend-mode: difference}');
  91. addGlobalStyles('body>table>tbody>tr>td.outer>span {mix-blend-mode: difference}');
  92. addGlobalStyles('body>table>tbody>tr>td.embedded {mix-blend-mode: screen}');
  93. } else {
  94. addGlobalStyles('table[cellpadding="10"][bgcolor="red"] {mix-blend-mode: difference}');
  95. addGlobalStyles('table[width="660"][cellpadding="10"] tbody tr[style="background-color: #008000; color: #fff;"] {mix-blend-mode: difference}');
  96. addGlobalStyles('body>table>tbody>tr>td.outer>span {mix-blend-mode: difference}');
  97. addGlobalStyles('body>table>tbody>tr>td.embedded {mix-blend-mode: screen}');
  98. addGlobalStyles('div[style="width: 75%; background-color: #f9f; padding: 5px; margin: 5px; color: #000;"] {mix-blend-mode: difference}');
  99. }
  100. }
  101.  
  102. function siteSC() {
  103. addGlobalStyles('img {mix-blend-mode: screen}');
  104. addGlobalStyles('#header {background: white}');
  105. addGlobalStyles('.colhead_dark {mix-blend-mode: difference}');
  106. addGlobalStyles('.fronttab {mix-blend-mode: exclusion}');
  107. addGlobalStyles('.colhead {mix-blend-mode: difference}');
  108. addGlobalStyles('.settings_sidebar {isolation: isolate}');
  109. addGlobalStyles('#textarea_wrap_0 {isolation: isolate}');
  110. addGlobalStyles('.widethin .header .topbar {mix-blend-mode: difference}');
  111. addGlobalStyles('.torrent_description table tbody tr {mix-blend-mode: difference}');
  112. addGlobalStyles('#covers #cover_div_0 .brackets {mix-blend-mode: normal}');
  113. addGlobalStyles('.wrapicon {mix-blend-mode: normal}');
  114. addGlobalStyles('.potwicon {mix-blend-mode: normal}');
  115. addGlobalStyles('iframe {mix-blend-mode: screen}');
  116. addGlobalStyles('.noty_buttons {mix-blend-mode: difference}');
  117. addGlobalStyles('.torrentdetails blockquote {background-color: white}');
  118. addGlobalStyles('label.collage_button {background: grey}');
  119. }
  120.  
  121. function siteDoom9() {
  122. addGlobalStyles('img {mix-blend-mode: screen}');
  123. addGlobalStyles('#vB_Editor_QR_cmd_removeformat img, \
  124. #vB_Editor_QR_cmd_bold img, \
  125. #vB_Editor_QR_cmd_italic img, \
  126. #vB_Editor_QR_cmd_underline img, \
  127. #vB_Editor_QR_color_out img \
  128. {mix-blend-mode: normal}');
  129. addGlobalStyles('#vB_Editor_001_controls img {mix-blend-mode: normal}');
  130. addGlobalStyles('#vB_Editor_001_popup_smilie img, \
  131. #vB_Editor_001_cmd_createlink img, \
  132. #vB_Editor_001_cmd_unlink img, \
  133. #vB_Editor_001_cmd_email img, \
  134. #vB_Editor_001_cmd_insertimage img, \
  135. #vB_Editor_001_cmd_wrap0_quote img, \
  136. #vB_Editor_001_cmd_wrap0_php img \
  137. {mix-blend-mode: screen}');
  138. }
  139.  
  140. function siteGreasyfork() {
  141. addGlobalStyles('img {mix-blend-mode: screen}');
  142. addGlobalStyles('#main-header {background: #66ffff}');
  143. addGlobalStyles('#site-name a img {mix-blend-mode: normal}');
  144. addGlobalStyles('#site-name img {mix-blend-mode: normal}');
  145. addGlobalStyles('#install-area {mix-blend-mode: difference}');
  146. addGlobalStyles('.script-list-ratings span span {mix-blend-mode: difference}');
  147. addGlobalStyles('.current {color: #bfbfbf}');
  148. addGlobalStyles('#about-user {background-color: transparent}');
  149. addGlobalStyles('#about-user h2 {color: #bfbfbf}');
  150. addGlobalStyles('#about-user h3 {color: #bfbfbf}');
  151. }
  152.  
  153. function siteUnknown() {
  154. addGlobalStyles('img {mix-blend-mode: screen}');
  155. }
  156.  
  157. //==============================================================================
  158. // Toggle/Add/Remove funcs.
  159. //==============================================================================
  160.  
  161. function addGlobalStyles(css) {
  162. var head, style;
  163. head = document.getElementsByTagName('head')[0];
  164. if (!head) { return; }
  165. style = document.createElement('style');
  166. style.className = 'DarkmodeUser';
  167. style.innerHTML = css;
  168. head.appendChild(style);
  169. }
  170.  
  171. function removeGlobalStyles() {
  172. var removeEl = [].slice.apply(document.getElementsByClassName("DarkmodeUser"));
  173. for (var i = 0; i < removeEl.length; i++) {
  174. removeEl[i].remove();
  175. }
  176. }
  177.  
  178. function toggleGlobalStyles() {
  179. var modestate = window.localStorage['darkmode'];
  180. if (modestate == "true") {
  181. addBackground();
  182. const urlHost = window.location.hostname;
  183. if (urlHost == 'karagarga.in') {
  184. siteKG();
  185. } else if (urlHost == 'secret-cinema.pw') {
  186. siteSC();
  187. } else if (urlHost == 'forum.doom9.org') {
  188. siteDoom9();
  189. } else if (urlHost == 'greasyfork.org') {
  190. siteGreasyfork();
  191. } else {
  192. siteUnknown();
  193. }
  194. } else {
  195. removeGlobalStyles();
  196. removeBackground();
  197. }
  198. }
  199.  
  200. function removeBackground() {
  201. console.log("Darkmode User (removeBackground): Started.");
  202. document.getElementsByClassName('darkmode-background')[0].remove();
  203. }
  204.  
  205. function addBackground() {
  206. if (document.querySelector('.darkmode-background') !== null) { return; }
  207. var backgroundDiv = document.createElement('div');
  208. backgroundDiv.setAttribute('class', 'darkmode-background');
  209. document.body.insertBefore(backgroundDiv, document.body.firstChild);
  210. }
  211.  
  212. //==============================================================================
  213. // Darkmode.js
  214. //==============================================================================
  215.  
  216. function addDarkmodeWidget() {
  217. const options = {
  218. bottom: '32px',
  219. right: '32px',
  220. left: 'unset',
  221. time: '0.0s',
  222. mixColor: '#fff',
  223. backgroundColor: '#fff',
  224. buttonColorDark: '#333333',
  225. buttonColorLight: '#b3b3b3',
  226. saveInCookies: true,
  227. label: '',
  228. autoMatchOsTheme: false
  229. };
  230. new Darkmode(options).showWidget();
  231. // Add func to the widged button to toggle styles on click.
  232. document.getElementsByClassName('darkmode-toggle')[0].onclick = function () {toggleGlobalStyles()};
  233. // Add styles on the page load.
  234. const darkmode = window.localStorage['darkmode'];
  235. if (darkmode == "true") {
  236. toggleGlobalStyles();
  237. } else {
  238. // Remove custom white background.
  239. removeBackground();
  240. }
  241. }
  242.  
  243. if (Boolean(location.href.match('karagarga.in/details.php' )) ||
  244. Boolean(location.href.match('karagarga.in/reqdetails.php')) ) {
  245. document.events.on('bodyloaded', () => {
  246. addDarkmodeWidget();
  247. });
  248. } else if (Boolean(location.href.match('karagarga.in/userdetails.php')) ||
  249. Boolean(location.href.match('karagarga.in/comment.php')) ||
  250. Boolean(location.href.match('karagarga.in/adsearch.php')) ||
  251. Boolean(location.href.match('karagarga.in/my.php')) ) {
  252. window.addEventListener('DOMContentLoaded', addDarkmodeWidget);
  253.  
  254. } else if (Boolean(location.href.match('karagarga.in'))) {
  255. document.events.on('bodyloaded', () => {
  256. addDarkmodeWidget();
  257. });
  258. } else {
  259. document.events.on('headloaded', () => {
  260. addDarkmodeWidget();
  261. });
  262. }