Youtube Old Site Design

Restore Youtube's Old Site Design

  1. // ==UserScript==
  2. // @name Youtube Old Site Design
  3. // @namespace https://twitter.com/collinchaffin
  4. // @description Restore Youtube's Old Site Design
  5. // @author Collin Chaffin
  6. // @include http://www.youtube.com/*
  7. // @include https://www.youtube.com/*
  8. // @homepage https://twitter.com/collinchaffin
  9. // @run-at document-start
  10. // @grant none
  11. // @version 1.0.4
  12. // @history Initial release
  13. // @history URL change is no longer needed
  14. // @history On 08-16-2018 Youtube borked it's layout - added fix
  15. // @history Fix requires waiting for dom elements removing from this script to avoid having to add external handlers at this time
  16. // @history Re-added new code to properly fix the 08-16-2018 layout issue (thanks to reddit user pop1040 for posting the code)
  17.  
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22. //BEGIN LOGGING
  23. var date = new Date();
  24. date.setTime(date.getTime());
  25. console.log(date);
  26. console.log('BEGIN :: Youtube Old Site Design Script...');
  27. console.log('------------------------------------------');
  28.  
  29. //GLOBAL VARIABLES TO CHANGE IF NEEDED
  30. var targetPrefs={'f5':'30030','f6':'8'};
  31. //Fix the URL:
  32. // NOTE: Once this is changed and refreshed, it is normal to see youtube remove the
  33. // appended parameter(s) after the redirect
  34. //
  35. // NOTE: NO LONGER NEEDED!! HERE FOR HISTORICAL PURPOSES ONLY!!
  36. /*
  37. var ytUrl=window.location.href;
  38. if (ytUrl.indexOf('disable_polymer')===-1){
  39. if (ytUrl.indexOf('?') > 0) {
  40. ytUrl+='&';
  41. } else {
  42. ytUrl+='?';
  43. }
  44. console.log('Fixing URL');
  45. ytUrl+='disable_polymer=1';
  46. window.location.href=ytUrl;
  47. }
  48. */
  49. //Fix the cookie:
  50. // Loop through every param/value only under PREF (once verified is set) and
  51. // for each of the global PREF values (targetPrefs), either change or add as necessary
  52. var prefStr=document.cookie.split(' ').filter(o=>o.indexOf('PREF=')!==-1)[0] || 'PREF=';
  53. var prefEntries=prefStr.substr(5).split('&');
  54. var found=false;
  55. var changed=false;
  56. for (var i=0; i<prefEntries.length; i++) {
  57. for(let [key,value] of Object.entries(targetPrefs)) {
  58. var found=false;
  59. for (var i=0; i<prefEntries.length; i++) {
  60. if (prefEntries[i].indexOf(key) === 0) {
  61. found=true;
  62. if (prefEntries[i].substr(key.length+1)!==value) {
  63. console.log('Fixing ' + key);
  64. prefEntries[i] = value;
  65. changed=true;
  66. }
  67. }
  68. }
  69. if (!found) {
  70. console.log('Adding '+key);
  71. prefEntries.push(key+'='+value);
  72. changed=true;
  73. }
  74. }
  75. }
  76. //Fix the most recent layout blunder (will not make change if okay!):
  77. //Credit to reddit user pop1040 for offering up with this code to work with running on-start compatible with this script
  78. //for correcting on navigation to a new video
  79. window.addEventListener("spfdone", function(e){
  80. if(!document.getElementById("content").classList.contains('content-alignment')){
  81. document.getElementById('content').classList.add('content-alignment');
  82. console.log('Fixing wide layout issue');
  83. }
  84. });
  85.  
  86. //for when you load a video directly
  87. window.addEventListener("load", function(event) {
  88. if(!document.getElementById("content").classList.contains('content-alignment')){
  89. document.getElementById('content').classList.add('content-alignment');
  90. console.log('Fixing wide layout issue');
  91. }
  92. });
  93. //Commit or do nothing:
  94. // Did we change anything? If so, commit the change and refresh the page, otherwise do nothing
  95. if (changed) {
  96. var newCookie='PREF=' + prefEntries.join('&') + ';domain=.youtube.com;path=/';
  97. console.log('Writing changed preference cookie with: '+ newCookie);
  98. document.cookie=newCookie;
  99. window.setTimeout(location.reload.bind(location,true),100);
  100. }
  101. //FINISH LOGGING
  102. console.log('FINISH :: Youtube Old Site Design Script...');
  103. console.log('-------------------------------------------');
  104. })();