YT - Old design

Activates the old YouTube design without messing with your other settings

This script is marked as "broken" and is likely not working
Details: Youtube removed the old design completely. This script does not works anymore
Click here to install Browse More Scripts
// ==UserScript==
// @name         YT - Old design
// @namespace    4c5725cd7d4b94b6f1784e759d5a43fbdd917971
// @version      0.5
// @description  Activates the old YouTube design without messing with your other settings
// @author       /u/AyrA_ch
// @match        https://www.youtube.com/*
// @match        http://www.youtube.com/*
// @match        https://youtube.com/*
// @match        http://youtube.com/*
// @grant        none
// @run-at       document-start
// @expired      true
// @broken       Youtube removed the old design completely. This script does not works anymore
// ==/UserScript==

// Changelog
// 0.5 More consistent logger
// 0.4 Rewrite all links to add the "no polymer argument"
// 0.3 Much more aggressive redirecting
// 0.2 Changed title to match other scripts
// 0.1 Initial Version

(function () {
    var log = function () {
        var args = ["YT Old Design:"].concat(Array.prototype.slice.call(arguments, 0));
        console.log.apply(console, args);
    };
    document.addEventListener("DOMContentLoaded", function () {
        var poly = /[&?]disable_polymer=1/;
        var current = location.href.replace(poly, '');
        var body = document.querySelector("body");
        var redir = function () {
            log("Redirecting to old design.", location.href);
            if (location.search.length > 1) {
                location.search += "&disable_polymer=1";
            } else {
                location.search = "?disable_polymer=1";
            }
        };

        var updateLinks = function () {
            var count = 0;
            var total = 0;
            document.querySelectorAll("a").forEach(function (v) {
                var link = v.href;
                ++total;
                if (link) {
                    if (!link.match(poly)) {
                        v.href += (link.indexOf('?') >= 0 ? '&' : '?') + "disable_polymer=1";
                        ++count;
                    }
                }
            });
            if (count > 0) {
                log("Rewrote", count, "links out of", total);
            }
        };

        var mo = new MutationObserver(function () {
            //Navigate only if the polymer string is not present and the URL differs from the current URL
            mo.disconnect();
            if (!location.href.match(poly) && location.href.replace(poly, '') !== current) {
                redir();
            } else {
                updateLinks();
                mo.observe(body, {
                    childList: true,
                    subtree: true
                });
            }
        });

        mo.observe(body, {
            childList: true,
            subtree: true
        });

        log("Waiting for URL changes");
        if (!location.href.match(poly)) {
            redir();
        }
    });

    var getDesignCookie = function (cookie) {
        //Find existing preferences
        var prefs = cookie.split("; ").filter(function (v) {
            return v.indexOf("PREF=") === 0;
        })[0];
        //No preferences, return new ones with design setting
        if (!prefs) {
            log("prefs not set in cookie");
            return "PREF=f6=8";
        }
        //Process all settings
        var entries = prefs.substr(5).split('&');
        var set = false;
        for (var i = 0; i < entries.length; i++) {
            if (entries[i].indexOf("f6=") === 0) {
                set = true;
                //Set the old design flag
                var value = +entries[i].substr(3);
                if ((value & 8) === 0) {
                    log("Activating old design and reloading...");
                    entries[i] = "f6=" + (value | 8);
                    window.setTimeout(location.reload.bind(location, true), 100);
                } else {
                    log("Old design already active. Doing nothing");
                }
            }
        }
        //Design flag setting doesn't exists. Adding it instead
        if (!set) {
            log("Activating old design and reloading...");
            entries.push("f6=8");
            window.setTimeout(location.reload.bind(location, true), 100);
        }
        //Build cookie
        return "PREF=" + entries.join('&');
    };
    //Update cookie
    document.cookie = getDesignCookie(document.cookie) + ";domain=.youtube.com;path=/";
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 18.218.241.155