Forked from CollinChaffin/Youtube-Old-Site-Design.user.js
Created
July 8, 2018 04:36
-
-
Save Mostha/649a80d4d8636a28299acc0e82b32f98 to your computer and use it in GitHub Desktop.
Youtube-Old-Site-Design.user.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Youtube Old Site Design | |
// @namespace https://twitter.com/collinchaffin | |
// @description Restore Youtube's Old Site Design | |
// @author Collin Chaffin | |
// @include http://www.youtube.com/* | |
// @include https://www.youtube.com/* | |
// @homepage https://twitter.com/collinchaffin | |
// @run-at document-start | |
// @grant none | |
// @updateURL https://git.io/ytosd | |
// @downloadURL https://git.io/ytosd | |
// @version 1.0.0 | |
// @history Initial release | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
//BEGIN LOGGING | |
var date = new Date(); | |
date.setTime(date.getTime()); | |
console.log(date); | |
console.log('BEGIN :: Youtube Old Site Design Script...'); | |
console.log('------------------------------------------'); | |
//GLOBAL VARIABLES TO CHANGE IF NEEDED | |
var targetPrefs={'f5':'30030','f6':'8'}; | |
//Fix the URL: | |
// NOTE: Once this is changed and refreshed, it is normal to see youtube remove the | |
// appended parameter(s) after the redirect | |
var ytUrl=window.location.href; | |
if (ytUrl.indexOf('disable_polymer')===-1){ | |
if (ytUrl.indexOf('?') > 0) { | |
ytUrl+='&'; | |
} else { | |
ytUrl+='?'; | |
} | |
console.log('Fixing URL'); | |
ytUrl+='disable_polymer=1'; | |
window.location.href=ytUrl; | |
} | |
//Fix the cookie: | |
// Loop through every param/value only under PREF (once verified is set) and | |
// for each of the global PREF values (targetPrefs), either change or add as necessary | |
var prefStr=document.cookie.split(' ').filter(o=>o.indexOf('PREF=')!==-1)[0] || 'PREF='; | |
var prefEntries=prefStr.substr(5).split('&'); | |
var found=false; | |
var changed=false; | |
for (var i=0; i<prefEntries.length; i++) { | |
for(let [key,value] of Object.entries(targetPrefs)) { | |
var found=false; | |
for (var i=0; i<prefEntries.length; i++) { | |
if (prefEntries[i].indexOf(key) === 0) { | |
found=true; | |
if (prefEntries[i].substr(key.length+1)!==value) { | |
console.log('Fixing ' + key); | |
prefEntries[i] = value; | |
changed=true; | |
} | |
} | |
} | |
if (!found) { | |
console.log('Adding '+key); | |
prefEntries.push(key+'='+value); | |
changed=true; | |
} | |
} | |
} | |
//Commit or do nothing: | |
// Did we change anything? If so, commit the change and refresh the page, otherwise do nothing | |
if (changed) { | |
var newCookie='PREF=' + prefEntries.join('&') + ';domain=.youtube.com;path=/'; | |
console.log('Writing changed preference cookie with: '+ newCookie); | |
document.cookie=newCookie; | |
window.setTimeout(location.reload.bind(location,true),100); | |
} | |
//FINISH LOGGING | |
console.log('FINISH :: Youtube Old Site Design Script...'); | |
console.log('-------------------------------------------'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment