YouTube - Revert old colors style script

This reverts back to the colors before the web_darker_dark_theme flag was enabled.

  1. // ==UserScript==
  2. // @name YouTube - Revert old colors style script
  3. // @version 2024.08.12
  4. // @description This reverts back to the colors before the web_darker_dark_theme flag was enabled.
  5. // @author Magma_Craft
  6. // @icon https://www.youtube.com/favicon.ico
  7. // @namespace https://greasyfork.org/en/users/933798
  8. // @license MIT
  9. // @match https://*.youtube.com/*
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. // Attributes to remove from <html>
  15. const ATTRS = [
  16. "darker-dark-theme",
  17. "darker-dark-theme-deprecate"
  18. ];
  19.  
  20. // Regular config keys.
  21. const CONFIGS = {
  22. };
  23.  
  24. // Experiment flags.
  25. const EXPFLAGS = {
  26. // Disable both 'darker_dark_theme' and 'amsterdam_playlists' (both have been patched since May and Nov '23)
  27. web_darker_dark_theme: false,
  28. web_amsterdam_playlists: false,
  29. // Disable the refresh on theme change (this have been patched since Apr '23)
  30. kevlar_refresh_on_theme_change: false,
  31. // Remove the ambient mode if you are on both dark theme (and theater mode)
  32. kevlar_watch_cinematics: false
  33. };
  34.  
  35. // Player flags
  36. // !!! USE STRINGS FOR VALUES !!!
  37. // For example: "true" instead of true
  38. const PLYRFLAGS = {
  39. };
  40.  
  41. class YTP {
  42. static observer = new MutationObserver(this.onNewScript);
  43.  
  44. static _config = {};
  45.  
  46. static isObject(item) {
  47. return (item && typeof item === "object" && !Array.isArray(item));
  48. }
  49. static mergeDeep(target, ...sources) {
  50. if (!sources.length) return target;
  51. const source = sources.shift();
  52. if (this.isObject(target) && this.isObject(source)) {
  53. for (const key in source) {
  54. if (this.isObject(source[key])) {
  55. if (!target[key]) Object.assign(target, { [key]: {} });
  56. this.mergeDeep(target[key], source[key]);
  57. } else {
  58. Object.assign(target, { [key]: source[key] });
  59. }
  60. }
  61. }
  62. return this.mergeDeep(target, ...sources);
  63. }
  64.  
  65. static onNewScript(mutations) {
  66. for (var mut of mutations) {
  67. for (var node of mut.addedNodes) {
  68. YTP.bruteforce();
  69. }
  70. }
  71. }
  72.  
  73. static start() {
  74. this.observer.observe(document, {childList: true, subtree: true});
  75. }
  76. static stop() {
  77. this.observer.disconnect();
  78. }
  79.  
  80. static bruteforce() {
  81. if (!window.yt) return;
  82. if (!window.yt.config_) return;
  83.  
  84. this.mergeDeep(window.yt.config_, this._config);
  85. }
  86.  
  87. static setCfg(name, value) {
  88. this._config[name] = value;
  89. }
  90.  
  91. static setCfgMulti(configs) {
  92. this.mergeDeep(this._config, configs);
  93. }
  94.  
  95. static setExp(name, value) {
  96. if (!("EXPERIMENT_FLAGS" in this._config)) this._config.EXPERIMENT_FLAGS = {};
  97.  
  98. this._config.EXPERIMENT_FLAGS[name] = value;
  99. }
  100.  
  101. static setExpMulti(exps) {
  102. if (!("EXPERIMENT_FLAGS" in this._config)) this._config.EXPERIMENT_FLAGS = {};
  103.  
  104. this.mergeDeep(this._config.EXPERIMENT_FLAGS, exps);
  105. }
  106.  
  107. static decodePlyrFlags(flags) {
  108. var obj = {},
  109. dflags = flags.split("&");
  110.  
  111. for (var i = 0; i < dflags.length; i++) {
  112. var dflag = dflags[i].split("=");
  113. obj[dflag[0]] = dflag[1];
  114. }
  115. return obj;
  116. }
  117.  
  118. static encodePlyrFlags(flags) {
  119. var keys = Object.keys(flags),
  120. response = "";
  121.  
  122. for (var i = 0; i < keys.length; i++) {
  123. if (i > 0) {
  124. response += "&";
  125. }
  126. response += keys[i] + "=" + flags[keys[i]];
  127. }
  128.  
  129. return response;
  130. }
  131.  
  132. static setPlyrFlags(flags) {
  133. if (!window.yt) return;
  134. if (!window.yt.config_) return;
  135. if (!window.yt.config_.WEB_PLAYER_CONTEXT_CONFIGS) return;
  136. var conCfgs = window.yt.config_.WEB_PLAYER_CONTEXT_CONFIGS;
  137. if (!("WEB_PLAYER_CONTEXT_CONFIGS" in this._config)) this._config.WEB_PLAYER_CONTEXT_CONFIGS = {};
  138.  
  139. for (var cfg in conCfgs) {
  140. var dflags = this.decodePlyrFlags(conCfgs[cfg].serializedExperimentFlags);
  141. this.mergeDeep(dflags, flags);
  142. this._config.WEB_PLAYER_CONTEXT_CONFIGS[cfg] = {
  143. serializedExperimentFlags: this.encodePlyrFlags(dflags)
  144. }
  145. }
  146. }
  147. }
  148.  
  149. window.addEventListener("yt-page-data-updated", function tmp() {
  150. YTP.stop();
  151. for (i = 0; i < ATTRS.length; i++) {
  152. document.getElementsByTagName("html")[0].removeAttribute(ATTRS[i]);
  153. }
  154. window.removeEventListener("yt-page-date-updated", tmp);
  155. });
  156.  
  157. YTP.start();
  158.  
  159. YTP.setCfgMulti(CONFIGS);
  160. YTP.setExpMulti(EXPFLAGS);
  161.  
  162. (function() {
  163. let css = `
  164. html[dark] { --yt-spec-general-background-a: #181818 !important; --yt-spec-general-background-b: #0f0f0f !important; --yt-spec-brand-background-primary: rgba(33, 33, 33, 0.98) !important; --yt-spec-10-percent-layer: rgba(255, 255, 255, 0.1) !important }
  165. html:not([dark]) { --yt-spec-general-background-a: #f9f9f9 !important; --yt-spec-general-background-b: #f1f1f1 !important; --yt-spec-brand-background-primary: rgba(255, 255, 255, 0.98) !important; --yt-spec-10-percent-layer: rgba(0, 0, 0, 0.1) !important }
  166.  
  167. /* Removes ambient mode if dark theme was enabled */
  168. #cinematics.ytd-watch-flexy { display: none !important }
  169.  
  170. /* Button improvements (including edit and sponsor buttons) */
  171. #voice-search-button.ytd-masthead { background-color: var(--yt-spec-general-background-a) !important; margin-left: 4px !important }
  172. #edit-buttons > ytd-button-renderer > yt-button-shape > a { color: var(--yt-spec-text-primary-inverse) !important; background-color: var(--yt-spec-call-to-action) !important }
  173. div#sponsor-button.style-scope.ytd-video-owner-renderer > ytd-button-renderer.style-scope.ytd-video-owner-renderer > yt-button-shape > .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--outline { background-color: var(--yt-spec-badge-chip-background) !important; border: none !important; color: var(--yt-spec-text-primary) !important }
  174. div#sponsor-button.style-scope.ytd-c4-tabbed-header-renderer > ytd-button-renderer.style-scope.ytd-c4-tabbed-header-renderer > yt-button-shape > .yt-spec-button-shape-next--mono.yt-spec-button-shape-next--outline { background-color: var(--yt-spec-badge-chip-background) !important; border: none !important; color: var(--yt-spec-text-primary) !important }
  175. button.yt-spec-button-shape-next.yt-spec-button-shape-next--outline.yt-spec-button-shape-next--mono.yt-spec-button-shape-next--size-m[aria-label="Join this channel"] { background-color: var(--yt-spec-badge-chip-background) !important; border: none !important; color: var(--yt-spec-text-primary) !important }
  176.  
  177. /* Apply the old colored theme */
  178. ytd-masthead { background: var(--yt-spec-brand-background-solid) !important }
  179. ytd-app { background: var(--yt-spec-general-background-a) !important }
  180. ytd-browse[page-subtype="channels"] { background: var(--yt-spec-general-background-b) !important }
  181. ytd-c4-tabbed-header-renderer { --yt-lightsource-section1-color: var(--yt-spec-general-background-a) !important }
  182. ytd-mini-guide-renderer, ytd-mini-guide-entry-renderer { background-color: var(--yt-spec-brand-background-solid) !important }
  183. #tabs-divider.ytd-c4-tabbed-header-renderer { border-bottom: 0px !important }
  184. #header.ytd-rich-grid-renderer { width: 100% !important }
  185. [page-subtype="home"] #chips-wrapper.ytd-feed-filter-chip-bar-renderer { background-color: var(--yt-spec-brand-background-primary) !important; border-top: 1px solid var(--yt-spec-10-percent-layer) !important; border-bottom: 1px solid var(--yt-spec-10-percent-layer) !important }
  186. ytd-feed-filter-chip-bar-renderer[is-dark-theme] #left-arrow.ytd-feed-filter-chip-bar-renderer::after { background: linear-gradient(to right, var(--yt-spec-brand-background-primary) 20%, rgba(33, 33, 33, 0) 80%) !important }
  187. ytd-feed-filter-chip-bar-renderer[is-dark-theme] #right-arrow.ytd-feed-filter-chip-bar-renderer::before { background: linear-gradient(to left, var(--yt-spec-brand-background-primary) 20%, rgba(33, 33, 33, 0) 80%) !important }
  188. ytd-feed-filter-chip-bar-renderer #left-arrow-button.ytd-feed-filter-chip-bar-renderer, ytd-feed-filter-chip-bar-renderer #right-arrow-button.ytd-feed-filter-chip-bar-renderer { background-color: var(--yt-spec-brand-background-primary) !important }
  189. yt-chip-cloud-renderer[is-dark-theme] #right-arrow.yt-chip-cloud-renderer::before { background: linear-gradient(to left, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(24, 24, 24, 0) 90%) !important; }
  190. yt-chip-cloud-renderer #left-arrow-button.yt-chip-cloud-renderer, yt-chip-cloud-renderer #right-arrow-button.yt-chip-cloud-renderer { background: var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) !important }
  191. yt-chip-cloud-renderer[is-dark-theme] #left-arrow.yt-chip-cloud-renderer::after { background: linear-gradient(to right, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(24, 24, 24, 0) 90%) !important }
  192. yt-chip-cloud-renderer #left-arrow.yt-chip-cloud-renderer::after { background: linear-gradient(to right, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(249, 249, 249, 0) 90%) !important }
  193. yt-chip-cloud-renderer #right-arrow.yt-chip-cloud-renderer::before { background: linear-gradient(to left, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(249, 249, 249, 0) 90%) !important }
  194. ytd-feed-filter-chip-bar-renderer[component-style="FEED_FILTER_CHIP_BAR_STYLE_TYPE_HASHTAG_LANDING_PAGE"] #chips-wrapper.ytd-feed-filter-chip-bar-renderer, ytd-feed-filter-chip-bar-renderer[component-style="FEED_FILTER_CHIP_BAR_STYLE_TYPE_CHANNEL_PAGE_GRID"] #chips-wrapper.ytd-feed-filter-chip-bar-renderer { background-color: var(--yt-spec-general-background-b) !important }
  195. ytd-watch-flexy #left-arrow.ytd-feed-filter-chip-bar-renderer:after { background: linear-gradient(to right, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(249, 249, 249, 0) 90%) !important; }
  196. ytd-watch-flexy #right-arrow.ytd-feed-filter-chip-bar-renderer:before { background: linear-gradient(to left, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(249, 249, 249, 0) 90%) !important; }
  197. ytd-watch-flexy ytd-feed-filter-chip-bar-renderer[is-dark-theme] #left-arrow.ytd-feed-filter-chip-bar-renderer:after { background: linear-gradient(to right, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(24, 24, 24, 0) 90%) !important; }
  198. ytd-watch-flexy ytd-feed-filter-chip-bar-renderer[is-dark-theme] #right-arrow.ytd-feed-filter-chip-bar-renderer:before { background: linear-gradient(to left, var(--ytd-chip-cloud-background, var(--yt-spec-general-background-a)) 10%, rgba(24, 24, 24, 0) 90%) !important; }
  199. #guide-content.ytd-app { background: var(--yt-spec-brand-background-solid) !important }
  200. [page-subtype="history"] #page-header.ytd-tabbed-page-header { background-color: var(--yt-spec-general-background-a) !important; padding-top: 0 !important; padding-bottom: 0 !important }
  201. .page-header-view-model-wiz__page-header-title--page-header-title-large { margin-top: 24px !important; margin-bottom: 8px !important; color: var(--yt-spec-text-primary) !important; font-size: 1.6em !important; line-height: 1.4em !important; font-weight: 500 !important }
  202.  
  203. /* Revert non-amsterdam playlists UI */
  204. ytd-c4-tabbed-header-renderer[use-page-header-style] .page-header-banner.ytd-c4-tabbed-header-renderer { border-radius: 0px !important }
  205. ytd-browse[darker-dark-theme][page-subtype="playlist"], ytd-browse[darker-dark-theme][page-subtype="show"] { background-color: var(--yt-spec-general-background-b) !important; padding-top: 0 !important }
  206. ytd-two-column-browse-results-renderer.ytd-browse[background-refresh] { background-color: var(--yt-spec-general-background-b) !important }
  207. .yt-sans-20.yt-dynamic-sizing-formatted-string, .yt-sans-22.yt-dynamic-sizing-formatted-string, .yt-sans-24.yt-dynamic-sizing-formatted-string, .yt-sans-28.yt-dynamic-sizing-formatted-string, yt-text-input-form-field-renderer[component-style="INLINE_FORM_STYLE_TITLE"][amsterdam] tp-yt-paper-input.yt-text-input-form-field-renderer .input-content.tp-yt-paper-input-container > input { font-family: "Roboto", "Arial", sans-serif !important; font-size: 2.4rem !important; line-height: 3.2rem !important; font-weight: 400 !important }
  208. ytd-browse[page-subtype=playlist][amsterdam] { padding-top: 0 !important }
  209. ytd-browse[page-subtype=playlist] ytd-playlist-header-renderer.ytd-browse, ytd-browse[page-subtype=playlist] .page-header-sidebar.ytd-browse, ytd-browse[has-page-header-sidebar] ytd-playlist-header-renderer.ytd-browse, ytd-browse[has-page-header-sidebar] .page-header-sidebar.ytd-browse { margin-left: 0 !important; height: calc(100vh - var(--ytd-toolbar-height)) !important }
  210. .immersive-header-container.ytd-playlist-header-renderer { margin-bottom: 0 !important; border-radius: 0 !important }
  211. .image-wrapper.ytd-hero-playlist-thumbnail-renderer { border-radius: 0 !important }
  212. ytd-playlist-header-renderer, yt-formatted-string[has-link-only_]:not([force-default-style]) a.yt-simple-endpoint.yt-formatted-string:visited, .metadata-stats.ytd-playlist-byline-renderer, .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--text, ytd-text-inline-expander.ytd-playlist-header-renderer { color: var(--yt-spec-text-primary) !important; --ytd-text-inline-expander-button-color: var(--yt-spec-text-primary) !important }
  213. ytd-dropdown-renderer[no-underline] tp-yt-paper-dropdown-menu-light .tp-yt-paper-dropdown-menu-light[style-target=input], tp-yt-iron-icon.tp-yt-paper-dropdown-menu-light { color: var(--yt-spec-text-primary) !important }
  214. .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--tonal, .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--filled { background: transparent !important; color: var(--yt-spec-text-primary) !important; border-radius: 2px !important; text-transform: uppercase }
  215. .metadata-text-wrapper.ytd-playlist-header-renderer { --yt-endpoint-color: var(--yt-spec-text-primary) !important; --yt-endpoint-hover-color: var(--yt-spec-text-primary) !important }
  216. div.immersive-header-background-wrapper.style-scope.ytd-playlist-header-renderer > div { background: var(--yt-spec-general-background-a) !important }
  217. #contents > ytd-playlist-video-list-renderer { background: var(--yt-spec-general-background-b) !important; margin-right: 0px !important }
  218. ytd-browse[page-subtype=playlist] ytd-two-column-browse-results-renderer.ytd-browse, ytd-browse[has-page-header-sidebar] ytd-two-column-browse-results-renderer.ytd-browse, ytd-browse[page-subtype=playlist][amsterdam] #alerts.ytd-browse { padding-left: 360px !important; padding-right: 0px !important; margin-bottom: 0 !important }
  219. ytd-alert-with-button-renderer[type=INFO], ytd-alert-with-button-renderer[type=SUCCESS] { background: var(--yt-spec-general-background-a) !important }
  220. ytd-item-section-renderer.style-scope.ytd-section-list-renderer[page-subtype="playlist"] > #header.ytd-item-section-renderer > ytd-feed-filter-chip-bar-renderer { display: none !important }
  221. .yt-spec-button-shape-next--overlay.yt-spec-button-shape-next--tonal { background: var(--yt-spec-base-background) }
  222. iron-input.tp-yt-paper-input > input.tp-yt-paper-input, textarea.tp-yt-iron-autogrow-textarea { color: var(--yt-spec-text-primary) !important }
  223. #labelAndInputContainer.tp-yt-paper-input-container > label, #labelAndInputContainer.tp-yt-paper-input-container > .paper-input-label { color: var(--yt-spec-text-secondary) }
  224. .unfocused-line.tp-yt-paper-input-container, .focused-line.tp-yt-paper-input-container { border-bottom-color: var(--yt-spec-text-primary) !important }`;
  225. if (typeof GM_addStyle !== "undefined") {
  226. GM_addStyle(css);
  227. } else {
  228. let styleNode = document.createElement("style");
  229. styleNode.appendChild(document.createTextNode(css));
  230. (document.querySelector("head") || document.documentElement).appendChild(styleNode);
  231. }
  232. })();