YouTube patch collection

feel free to modify

  1. // ==UserScript==
  2. // @name YouTube patch collection
  3. // @version 0.1
  4. // @description feel free to modify
  5. // @author daylin
  6. // @match *://*.youtube.com/*
  7. // @match *://*.youtu.be/*
  8. // @icon https://www.youtube.com/favicon.ico
  9. // @run-at document-start
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/1132181
  12. // ==/UserScript==
  13.  
  14. // polyfill for chrome :vomit:
  15. (function() {
  16. if ("onbeforescriptexecute" in document) return;
  17.  
  18. let scriptWatcher = new MutationObserver(mutations => {
  19. for (let mutation of mutations) {
  20. for (let node of mutation.addedNodes) {
  21. if (node.tagName === "SCRIPT") {
  22. let syntheticEvent = new CustomEvent("beforescriptexecute", {
  23. detail: node,
  24. cancelable: true
  25. })
  26.  
  27. if (!document.dispatchEvent(syntheticEvent)) {
  28. node.remove();
  29. }
  30. }
  31. }
  32. }
  33. })
  34. scriptWatcher.observe(document, {
  35. childList: true,
  36. subtree: true
  37. })
  38. })();
  39.  
  40. (function() {
  41.  
  42. const EXP_MOD_POLYMER_JS = false;
  43. const OLD_POLYMER_JS_CONTENT = fetch("https://www.youtube.com/s/desktop/18069be1/jsbin/desktop_polymer.vflset/desktop_polymer.js");
  44.  
  45. function modifyJson(json) {
  46.  
  47. json.EXPERIMENT_FLAGS.kevlar_updated_logo_icons = false;
  48. json.EXPERIMENT_FLAGS.kevlar_updated_icons = false;
  49. json.EXPERIMENT_FLAGS.kevlar_system_icons = false;
  50. json.EXPERIMENT_FLAGS.kevlar_watch_color_update = false;
  51. json.EXPERIMENT_FLAGS.desktop_mic_background = false;
  52. json.EXPERIMENT_FLAGS.kevlar_unavailable_video_error_ui_client = false;
  53. json.EXPERIMENT_FLAGS.kevlar_center_search_results = false;
  54. json.EXPERIMENT_FLAGS.kevlar_watch_metadata_refresh = false;
  55. json.EXPERIMENT_FLAGS.web_snackbar_ui_refresh = false;
  56. json.EXPERIMENT_FLAGS.web_guide_ui_refresh = false;
  57. json.EXPERIMENT_FLAGS.web_sheets_ui_refresh = false;
  58. // json.EXPERIMENT_FLAGS.web_darker_dark_theme = true; //
  59.  
  60. json.WEB_PLAYER_CONTEXT_CONFIGS
  61. .WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH
  62. .serializedExperimentFlags = modifyPlayerExperiments(
  63. json.WEB_PLAYER_CONTEXT_CONFIGS
  64. .WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH
  65. .serializedExperimentFlags
  66. );
  67.  
  68. startHtmlMods();
  69.  
  70. // ------------------------------- //
  71.  
  72. return JSON.stringify(json);
  73. }
  74.  
  75. function modifyPlayerExperiments(text) {
  76. var flags = deserialiseFlags(text);
  77.  
  78. // perform your modifications here;
  79. // due to the encoding of these, the value
  80. // will always be a string (rather than a bool,
  81. // for instance)
  82.  
  83. flags.web_player_move_autonav_toggle = "false";
  84. flags.web_settings_menu_icons = "false";
  85.  
  86. // ------------------------------- //
  87.  
  88. var response = serialiseFlags(flags);
  89. return response;
  90. }
  91.  
  92. function serialiseFlags(json) {
  93. var keys = Object.keys(json),
  94. response = "";
  95.  
  96. for (var i = 0, j = keys.length; i < j; i++) {
  97. if (i > 0) {
  98. response += "&";
  99. }
  100. response += keys[i] + "=" + json[keys[i]];
  101. }
  102.  
  103. return response;
  104. }
  105.  
  106. function deserialiseFlags(text) {
  107.  
  108. var a = text.split("&"),
  109. obj = {};
  110.  
  111. for (var i = 0, j = a.length; i < j; i++) {
  112. var b = a[i].split("=");
  113. var key = b[0];
  114. var val = b[1];
  115. obj[key] = val;
  116. }
  117.  
  118. return obj;
  119. }
  120.  
  121. function extractYtConfigJson(text) {
  122. const open = "ytcfg.set(";
  123. const close = ");";
  124.  
  125. var a = text.split(open);
  126. var b = a[1].split(close);
  127. return b[0];
  128. }
  129.  
  130. function modifyYtConfig(text) {
  131. var originalJson = extractYtConfigJson(text);
  132. var parsedJson = JSON.parse(originalJson);
  133.  
  134. var modifiedJson = modifyJson(parsedJson);
  135.  
  136. var newText = text.replace(originalJson, modifiedJson);
  137. return newText;
  138. }
  139.  
  140. function startHtmlMods() {
  141. document.getElementsByTagName('html')[0].removeAttribute('system-icons');
  142. }
  143.  
  144. async function waitForElm(s) {
  145. while (document.querySelector(s) === null) {
  146. await new Promise(r => requestAnimationFrame(r))
  147. }
  148. return document.querySelector(s);
  149. }
  150.  
  151. async function modPolymerJs(srcUrl) {
  152. var a = document.createElement("script");
  153. a.src = srcUrl;
  154. document.body.appendChild(a);
  155. }
  156.  
  157. const handleScript = (e) => {
  158. let script = e.details || e.target;
  159.  
  160. if (script.textContent.search("ytcfg.set") > -1) {
  161. script.textContent = modifyYtConfig(script.textContent);
  162. } else if (EXP_MOD_POLYMER_JS && script.src.search("desktop_polymer") > -1) {
  163. script.textContent = OLD_POLYMER_JS_CONTENT;
  164. }
  165. };
  166.  
  167. document.addEventListener("beforescriptexecute", handleScript);
  168.  
  169. })();
  170.  
  171. (function() {var css = [
  172. "/*right column*/",
  173. " [d*=\"M10 14.65v-5.3L15 12l-5 2.65zm7.77-4.33c-.77-.32-1.2-.5-1.2-.5L18 9.06c1.84-.96 2.53-3.23 1.56-5.06s-3.24-2.53-5.07-1.56L6 6.94c-1.29.68-2.07 2.04-2 3.49.07 1.42.93 2.67 2.22 3.25.03.01 1.2.5 1.2.5L6 14.93c-1.83.97-2.53 3.24-1.56 5.07.97 1.83 3.24 2.53 5.07 1.56l8.5-4.5c1.29-.68 2.06-2.04 1.99-3.49-.07-1.42-.94-2.68-2.23-3.25zm-.23 5.86l-8.5 4.5c-1.34.71-3.01.2-3.72-1.14-.71-1.34-.2-3.01 1.14-3.72l2.04-1.08v-1.21l-.69-.28-1.11-.46c-.99-.41-1.65-1.35-1.7-2.41-.05-1.06.52-2.06 1.46-2.56l8.5-4.5c1.34-.71 3.01-.2 3.72 1.14.71 1.34.2 3.01-1.14 3.72L15.5 9.26v1.21l1.8.74c.99.41 1.65 1.35 1.7 2.41.05 1.06-.52 2.06-1.46 2.56z\"] {",
  174. " d: path(\"M17.77 10.32c-.77-.32-1.2-.5-1.2-.5L18 9.06c1.84-.96 2.53-3.23 1.56-5.06s-3.24-2.53-5.07-1.56L6 6.94c-1.29.68-2.07 2.04-2 3.49.07 1.42.93 2.67 2.22 3.25.03.01 1.2.5 1.2.5L6 14.93c-1.83.97-2.53 3.24-1.56 5.07.97 1.83 3.24 2.53 5.07 1.56l8.5-4.5c1.29-.68 2.06-2.04 1.99-3.49-.07-1.42-.94-2.68-2.23-3.25zM10 14.65v-5.3L15 12l-5 2.65z\")",
  175. " }"
  176. ].join("\n");
  177. if (typeof GM_addStyle != "undefined") {
  178. GM_addStyle(css);
  179. } else if (typeof PRO_addStyle != "undefined") {
  180. PRO_addStyle(css);
  181. } else if (typeof addStyle != "undefined") {
  182. addStyle(css);
  183. } else {
  184. var node = document.createElement("style");
  185. node.type = "text/css";
  186. node.appendChild(document.createTextNode(css));
  187. var heads = document.getElementsByTagName("head");
  188. if (heads.length > 0) {
  189. heads[0].appendChild(node);
  190. } else {
  191. // no head yet, stick it whereever
  192. document.documentElement.appendChild(node);
  193. }
  194. }
  195. })();