Codechef theme

dark theme for codeforces

  1. // ==UserScript==
  2. // @name Codechef theme
  3. // @version 2.0.0
  4. // @description dark theme for codeforces
  5. // @author Gaurang Tandon
  6. // @match https://codeforces.com/*
  7. // @match http://codeforces.com/*
  8. // @match https://www.codechef.com/*
  9. // @match https://calendar.google.com/calendar/embed*
  10. // @match https://www.facebook.com/v2.8/plugins/like.php*
  11. // @resource desertCSS desert.css
  12. // @resource monokaiEditorTheme https://raw.githubusercontent.com/ajaxorg/ace/master/lib/ace/theme/monokai.css
  13. // @resource darkthemecss darktheme.css
  14. // @grant GM_addStyle
  15. // @grant GM_getResourceText
  16. // @run-at document-start
  17. // @namespace https://gf.qytechs.cn/users/920052
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. "use strict";
  22.  
  23. var colors = {
  24. tableGreyRow: "#2e2e2e",
  25. whiteTextColor: "rgb(220, 220, 220)",
  26. inputBoxBackgroundBorderColor: "#383838",
  27. redColorJustPassesA11Y: "#ff3333",
  28. genericLinkBlueColor: "#4d9fef"
  29. };
  30.  
  31. function overrideStyleAttribute(elm, prop, value) {
  32. elm.setAttribute("style", elm.getAttribute("style") + `; ${prop}: ${value} !important; `);
  33. }
  34.  
  35. if (window.self != window.top && /calendar\.google\.com/.test(window.self.location.hostname)) {
  36. // cannot add the other styles as they interfere with
  37. // calendar's elements (since the selectors are so generic)
  38. GM_addStyle(`
  39. /* google calendar logo, see #13 */
  40. div.logo-plus-button {
  41. filter: invert(1) hue-rotate(180deg);
  42. }`);
  43. // rest of the google calendar has already been inverted
  44. // so return
  45. return;
  46. }
  47.  
  48. var style = GM_getResourceText("darkthemecss"),
  49. desertCSS = GM_getResourceText("desertCSS");
  50.  
  51. GM_addStyle(style);
  52. GM_addStyle(desertCSS);
  53.  
  54. // to avoid long FOUT duration
  55. function applyFuncWhenElmLoaded(sel, func) {
  56. var elm = document.querySelectorAll(sel);
  57. if (!elm || elm.length == 0) return setTimeout(applyFuncWhenElmLoaded, 100, sel, func);
  58. for (let i = 0, len = elm.length; i < len; i++) func(elm[i]);
  59. }
  60.  
  61. // some properties are added via element.style
  62. // need to override them via javascript
  63.  
  64. // div div h3 a = the top header "@user's blog" whose color property is added via js
  65. applyFuncWhenElmLoaded(
  66. "#pageContent div div h3 a, .comment-table.highlight-blue .right .ttypography p, .comment-table.highlight-blue .right .info",
  67. function (elm) {
  68. var obs = new MutationObserver(function (mutationList, observer) {
  69. mutationList.forEach(function (mutation) {
  70. if (mutation.type == "attributes" && mutation.attributeName == "style") {
  71. elm.setAttribute("style", elm.getAttribute("style") + "; color: white !important; ");
  72. }
  73. });
  74. });
  75. overrideStyleAttribute(elm, "color", "white");
  76.  
  77. obs.observe(elm, { attributes: true });
  78. }
  79. );
  80.  
  81. applyFuncWhenElmLoaded(".datatable div:nth-child(5)", function (elm) {
  82. elm.classList.add("dark");
  83. });
  84.  
  85. // in this case !important doesn't workthrough css stylesheet
  86. applyFuncWhenElmLoaded(".unread td", function (elm) {
  87. elm.style.backgroundColor = "#13203a !important";
  88. });
  89.  
  90. (function detect404Page() {
  91. applyFuncWhenElmLoaded("body > h3", function (elm) {
  92. if (elm.innerText.startsWith("The requested URL was not found on this server.")) {
  93. document.body.classList.add("notfoundpage");
  94. }
  95. });
  96. })();
  97.  
  98. (function fixLavaMenu() {
  99. applyFuncWhenElmLoaded(".second-level-menu-list li.backLava", function (elm) {
  100. elm.style.backgroundImage =
  101. "url(https://github.com/GaurangTandon/codeforces-darktheme/raw/master/imgs/lava-right2.png)";
  102. elm.firstElementChild.style.backgroundImage =
  103. "url(https://github.com/GaurangTandon/codeforces-darktheme/raw/master/imgs/lava-left2.png)";
  104. });
  105. })();
  106.  
  107. (function fixAceEditor() {
  108. applyFuncWhenElmLoaded("#editor", function (elm) {
  109. var monokaiEditorThemeCSS = GM_getResourceText("monokaiEditorTheme"),
  110. aceChromeClass = "ace-chrome";
  111. GM_addStyle(monokaiEditorThemeCSS);
  112. elm.classList.remove(aceChromeClass);
  113. elm.classList.add("ace-monokai");
  114.  
  115. // using a mutationobserver to revert addition of class ace-chome
  116. // goes into an infinite loop, presumably because the script run
  117. // by codeforces adds it back
  118. function checkAceClassRemoved() {
  119. if (elm.classList.contains(aceChromeClass)) {
  120. elm.classList.remove(aceChromeClass);
  121. }
  122. }
  123. setInterval(checkAceClassRemoved, 10);
  124. });
  125. })();
  126.  
  127. (function fixColorRedGreenContrast() {
  128. if (document.readyState != "complete") {
  129. return setTimeout(fixColorRedGreenContrast, 100);
  130. }
  131.  
  132. var elms = document.querySelectorAll("*");
  133. for (let i = 0, len = elms.length; i < len; i++) {
  134. if (getComputedStyle(elms[i]).color == "rgb(0, 128, 0)") {
  135. overrideStyleAttribute(elms[i], "color", "#00c700");
  136. }
  137. }
  138.  
  139. elms = document.querySelectorAll("font");
  140. for (let i = 0, len = elms.length; i < len; i++) {
  141. if (elms[i].getAttribute("color") == "red") {
  142. elms[i].setAttribute("color", colors.redColorJustPassesA11Y);
  143. }
  144. }
  145. })();
  146.  
  147. (function fixBlackTextInRightTableDuringContest() {
  148. applyFuncWhenElmLoaded(".rtable span", function (elm) {
  149. if (elm.style && elm.style.color == "rgb(0, 0, 0)")
  150. overrideStyleAttribute(elm, "color", colors.whiteTextColor);
  151. });
  152. })();
  153.  
  154. // cannot override through css since specifity issue
  155. (function improveLinkColorInGreenAlerts() {
  156. applyFuncWhenElmLoaded("div.alert-success a", function (elm) {
  157. overrideStyleAttribute(elm, "color", "#004794");
  158. });
  159. })();
  160. })();

QingJ © 2025

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