annnoyboy / YouTube old layout

// ==UserScript==
// @name         YouTube old layout
// @namespace    https://www.youtube.com/
// @version      0.1
// @description  Disables the new layout of YouTube.
// @author       Santanu
// @match        *://www.youtube.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    var updateUrl = updateQS(window.location.href, "disable_polymer", "true");
    document.execCommand('Stop');
    if (window.location.href != updateUrl) document.location = updateUrl;
    window.history.replaceState(null, null, window.location.href.replace(/[?|&]disable_polymer=(true|1)/i, ""));
})();

function updateQS(uri, key, value) {
    var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
    var separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
        return uri.replace(re, '$1' + key + "=" + value + '$2');
    } else {
        return uri + separator + key + "=" + value;
    }
}