Old Youtube Buttons

Changes various YouTube elements to resemble the old YouTube Design. (Green/Red Like/Dislike, Yellow Subscribe Button.)

当前为 2023-08-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Old Youtube Buttons
// @namespace    YellowSubButt
// @version      0.3.21
// @description  Changes various YouTube elements to resemble the old YouTube Design. (Green/Red Like/Dislike, Yellow Subscribe Button.)
// @author       SomeSchmuck
// @match        *://*.youtube.com/*
// @icon         https://th.bing.com/th/id/R.a12178dd72afd2470f0d2285602f2374?rik=%2fZTUzR2M%2fWKHUA&riu=http%3a%2f%2fsguru.org%2fwp-content%2fuploads%2f2018%2f02%2fYouTube_logo.png&ehk=kk7ZapiqeyJwuqO64Byiid8PbemJtRLsbmphetcvtcE%3d&risl=&pid=ImgRaw&r=0
// @grant        GM_addStyle
// @run-at       document-end
// @connect      youtube.com
// @license      MIT
// ==/UserScript==

// grant        GM.xmlHttpRequest TODO: is this needed?

// TODOs:
//    make the above section a little cleaner and see if certain parts are actually needed or not
//    maybe make this not use esversion 6? technically better browser support that way, although
//        that might not even be an issue... Too bad!
/* jshint esversion: 6 */

//known issues:
//sub button sometimes has a thin white/really bright line at the very bottom;
//  this might be a browser issue, though adjusting css padding can hide it a little bit

// 0.3.21 changes:
// improved script performance by limiting the amount of times the actually intensive parts of the script
//    performance wise can run in a single second; update rate is limited to at most twice in a second which should
//    realistically be more than enough
// slight code cleanup

// 0.3.20 changes:
// fixed subcribe button
// removed evtListen function since it was useless and unused

// 0.3.19 changes:
// Removed an unecessary eventListener; Because the script uses MutationObservers,
//    the script will automatically respond to changes no matter what, and we only
//    need to 'create' our MutationObserver once.
// Changed color of Reply buttons/text in the comments.
// Added initial support for multiple 'eras' of YouTube for the specific old designs/colours.
//    Currently, this functionality is NOT exposed to the users directly, and is only
//    configurable via script modification. This also only applies to the reply text formatting/
//    colours at the moment.
//    The main rationale behind adding this functionality if it is so limited is mainly so that
//    when more is done with it later, it will be easier (even if only slightly)
//    to properly fit into this script, as opposed to a major refactor/rewrite
//    to make it all work correctly.

// Supported values: 2008, 2012.
// TODO: Add support for design changes YouTube made during supported years, instead
// of a general hodgepodge of all the different designs ssen in one year.
var ytEra = 2008;
var lastTime = Date.now();
var delta = 0;
(function() {
    "use strict";
    locationChange();
    function set_join_buttons(){
        // remove any existing buttons with the 'oytJoin' id; this removes random
        // buttons that also get to look like the join button.
        let existJoins = document.querySelectorAll('#oytJoin');
        for (let i = 0; i < existJoins.length; i++){
            // console.log(existJoins[fj]);
            existJoins[i].removeAttribute('id');
        }
        let joinDivs = document.querySelectorAll('#sponsor-button');
        // console.log(joinDivs);
        for (let i = 0; i < joinDivs.length; i++){
            // console.log(joinDivs[jb].children.length);
            if (joinDivs[i].children.length > 0){
                let joinButton = joinDivs[i].getElementsByTagName('button')[0];
                // console.log(subButton);
                if (joinButton != undefined){
                    joinButton.setAttribute('id', 'oytJoin');
                    //TODO: implement support for having joined a channel.
                }
            }
        }
        //this might accidentally override a button we don't want to... Too bad!
        joinDivs = document.querySelectorAll('#purchase-button');
        for (let i = 0; i < joinDivs.length; i++){
            let purchaseButton = joinDivs[i].getElementsByTagName('button')[0];
            if (purchaseButton != undefined){
                purchaseButton.setAttribute('id', 'oytJoin');
                //TODO: implement support for having joined a channel.
            }
        }
    }
    //TODO: Fix comments text formatting
    function set_buttons_text(){
        let reply_info = document.getElementsByTagName('yt-formatted-string');
        //console.log(reply_info.length);
        if (reply_info.length != 0){
            for(let r = 0; r < reply_info.length; r++){
                let reply_str = reply_info[r].innerText.toLowerCase();
                const reply_style = 'border-bottom: 1px dotted #0140FF; color: #0140FF; text-transform: capitalize; font-weight: normal;';
                const join_text_style = 'color: #039';
                if (reply_str != null){
                    if (reply_str === 'reply'){
                        reply_info[r].setAttribute('style', reply_style);
                    } else if (reply_str === 'join' || reply_str === 'customize channel' || reply_str === 'manage videos'){
                        reply_info[r].setAttribute('style', join_text_style);
                    } else {
                        //if we don't pass above checks, remove styling. Youtube shouldn't have anything
                        // important formatted like this anyway, so we're... fine i think
                        reply_info[r].removeAttribute('style');
                    }
                }
            }
        }
    }
    function set_video_inf(){
        // set_video_buttons();
        // set_buttons_text();
        // setSubJoin();
        set_join_buttons();
    }
    // function addGlobalStyle(css) {
    //     let head, style, styles;
    //     //console.log(document.getElementsByTagName('head'))
    //     head = document.getElementsByTagName('head')[0];
    //     if (!head) { return; }
    //     styles = head.getElementsByClassName('yt_style');
    //     if (styles.length >= 1){ return; }
    //     style = document.createElement('style');
    //     style.type = 'text/css';
    //     style.setAttribute('class', "yt_style");
    //     style.innerHTML = css;
    //     head.appendChild(style);
    //     // console.log(head);
    // }
    function createStyle() {
        let style = '';
        // var style = '';
        //sub button; new YT ver
        style += '#subscribe-button > ytd-button-renderer > yt-button-shape > button, .style-scope.ytd-subscribe-button-renderer > button{background: linear-gradient(180deg, #fff9c1 0%, #fed81c 100%) !important; border: 1px solid #ecc101 !important; border-radius: 4px !important; color: #994800 !important; text-transform: capitalize !important; font-weight: bold !important; padding: 2px 9px 0 10px; height: 27px; font-family: Arial, sans-serif; font-size: 12px;}';
        style += '#subscribe-button > ytd-button-renderer > yt-button-shape > button:hover, .style-scope.ytd-subscribe-button-renderer > button:hover{background: linear-gradient(180deg, #fffffa 0%, #fed925 100%) !important; text-decoration: underline;}';
        //unsub button
        style += '#notification-preference-button > ytd-subscription-notification-toggle-button-renderer-next > yt-button-shape > button{background: linear-gradient(180deg, #fefefe 0%, #c2c2c2 100%) !important; color: #333 !important; border: 1px solid #ccc !important; border-radius: 4px !important; text-transform: capitalize !important; font-weight: bold !important; padding: 2px 9px 0 10px; height: 27px; font-family: Arial, sans-serif; font-size: 12px;}';
        style += '#notification-preference-button > ytd-subscription-notification-toggle-button-renderer-next > yt-button-shape > button:hover { background: linear-gradient(180deg, #fefefe 0%, #a8a6a6 100%) !important; }';
        //remove notif bell and dropdown arrow (maybe change arrow to something old style later?)
        style += '#notification-preference-button > ytd-subscription-notification-toggle-button-renderer-next > yt-button-shape > button > div.yt-spec-button-shape-next__icon{display: none;}';
        style += '#notification-preference-button > ytd-subscription-notification-toggle-button-renderer-next > yt-button-shape > button > div.yt-spec-button-shape-next__secondary-icon{display: none;}';
        //join button(s)
        style += '#oytJoin{background-image: linear-gradient(180deg, #fbfcff 0%, #93b2ff 100%) !important; color: #1c1b16 !important; font-size: 14px; text-transform: capitalize !important; font-weight: bold; font-family: Arial, sans-serif; height: 25px !important; border-radius: 4px !important; border-color: #8aa1d5 !important;}';
        //Likes-dislikes
        style += '#like-button{--yt-spec-text-primary: green !important;}';
        style += '#dislike-button{--yt-spec-text-primary: red !important;}';
           // New like buttons (more efficient than through JS lmao)
        style += '#segmented-like-button > ytd-toggle-button-renderer > yt-button-shape > button > .yt-spec-button-shape-next__icon > yt-icon > yt-animated-icon > ytd-lottie-player > lottie-component > svg > g > g > g > path{fill: green; stroke: green;}';
        style += '#segmented-like-button > ytd-toggle-button-renderer > yt-button-shape > button > .yt-spec-button-shape-next__icon > yt-icon{color: green;}';
        style += '#segmented-dislike-button > ytd-toggle-button-renderer > yt-button-shape > button > .yt-spec-button-shape-next__icon > yt-icon{color: red;}';
        // reply text styling
        let repCol = '#0140FF'; // default 2008 colour
        let repLapseCol = repCol;
        let repUnd = 'border-bottom: 1px dotted' + repCol + '; font-weight: normal;';
        if (ytEra == 2012) {
            repCol = '#999';
            repLapseCol = '#438bc5';
            repUnd = 'font-weight: bold; font-size: 11px; font-family: arial,sans-serif;';
            style += '#reply-button-end > ytd-button-renderer > yt-button-shape > button:hover > div > span {color: ' + repLapseCol + '; text-decoration: underline;}';
            // style += '.more-button.ytd-comment-replies-renderer:hover, .less-button.ytd-comment-replies-renderer:hover{--yt-spec-call-to-action: #438bc5;}';
            style += '.more-button.ytd-comment-replies-renderer:hover > yt-button-shape > button > div > span, .less-button.ytd-comment-replies-renderer:hover > yt-button-shape > button > div > span{text-decoration: underline;}';
            style += '.more-button.ytd-comment-replies-renderer > yt-button-shape > button > div > span, .less-button.ytd-comment-replies-renderer > yt-button-shape > button > div > span{' + repUnd + ' font-size: 12px;}';
        }
        style += '#reply-button-end > ytd-button-renderer > yt-button-shape > button > div > span{' + repUnd + 'color: ' + repCol + ';}';
        style += '#reply-button-end > ytd-button-renderer > yt-button-shape > button:hover{background-color: transparent;}';
        style += '.more-button.ytd-comment-replies-renderer, .less-button.ytd-comment-replies-renderer{--yt-spec-touch-response: transparent; --yt-spec-suggested-action: transparent; --yt-spec-call-to-action: ' + repLapseCol + ';}';
        return style;
    }
    //trick to make buttons that don't originally have hover css have hover css part 2 :)
    //addGlobalStyle('ytd-button-renderer #button.ytd-button-renderer[join]:hover { border-color: green !important;}')
    GM_addStyle(createStyle());
    //this bit of script was taken and modified from the script "Youtube: Download Video" by HayaoGai
    //link to that script: https://greasyfork.org/en/scripts/404304-youtube-download-video
    function locationChange() {
        //console.log('Switched page!');
        const observer = new MutationObserver(mutations => {
            // limit update rate
            let tempTime = Date.now();
            delta += tempTime - lastTime;
            lastTime = tempTime;
            if (delta >= 500) {
                set_video_inf();
                delta = 0; // reset delta time
            }
        });
        const target = document.body;
        const config = { childList: true, subtree: true };
        observer.observe(target, config);
    }
})();