YouTube Classic for 2018 (Polymer Disable)

Redirect YouTube pages to the classic design

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name YouTube Classic for 2018 (Polymer Disable)
// @namespace https://github.com/davidbailey95
// @version 0.2.0
// @description Redirect YouTube pages to the classic design
// @author /u/ndogw and davidbailey95
// @match *://www.youtube.com/*
// @exclude *://www.youtube.com/embed/*
// @run-at document-start
// @grant none
// ==/UserScript==
function changeUrl(url, always) {
    if (url.indexOf("disable_polymer") === -1) {
        if (url.indexOf("?") > 0) {
            url += "&";
        } else {
            url += "?";
        }
        url += "disable_polymer=1";
        window.location.href = url;
    }
    if (always) {
        window.location.href = url;
    }
}

var url = window.location.href;
changeUrl(url);

document.addEventListener('DOMContentLoaded', function() {
    // from https://stackoverflow.com/a/12552017/4247209
    document.body.onclick = function(e){
        e = e || event;
        var from = findParent('a',e.target || e.srcElement);
        if (from) {
            var url = from.href;
            if (!(url.match("/embed/") || url === location.href)) {
                changeUrl(url, true);
                return false;
            }
        }
    };
    //find first parent with tagName [tagname]
    function findParent(tagname,el){
        while (el){
            if ((el.nodeName || el.tagName).toLowerCase()===tagname.toLowerCase()){
                return el;
            }
            el = el.parentNode;
        }
        return null;
    }
});