Old Youtube Buttons

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

当前为 2022-10-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         Old Youtube Buttons
// @namespace    YellowSubButt
// @version      0.3.13
// @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.xmlHttpRequest
// @run-at       document-end
// @connect      youtube.com
// @license      MIT
// ==/UserScript==

// 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.13 change:
// Fixed a CSS typo.

// 0.3.12 changes:
// fixed support for newest YouTube UI; however, this removes support for the older UI.
//    users with the old UI still should remain on 0.3.11 for the time being.

// 0.3.11 changes:
// Made button that sets "join" button styling remove styling on button's that aren't the
// join button, so that hopefully, finally, for real, 100% this time the bug of the styling
// being on other buttons is fixed. (How to reproduce that bug for future refrence: Load a video
// by a channel with channel membership. Load a video from a channel that doesn't after. Scroll down to
// comments or click "not interested" on a video, and see if the "reply" and "undo" buttons respectively
// are styled like the join button.)

// 0.3.10 changes:
// only calls "set_video_inf" function once PER 'mutations' from mutationobserver;
//   before it would call the foreach function, which would itirate through all the
//   data in the mutations (basically an array) which could go into the hundreds at times,
//   while there could be more than dozens of mutations when going page to page
//   only calling it once gives a BIG performance jump, with basically no change to functionality
//   due to how the mutationobserver is used in the first place.

(function() {
    "use strict";
    window.addEventListener('yt-navigate-finish', evtListen, true);
    evtListen();
    // locationChange();
    function set_video_buttons(){
        var new_video_info = document.getElementsByClassName('item style-scope ytd-watch-metadata');
        if (new_video_info.length >= 1){
            // console.warn("new youtube layout detected!")
            // console.log(new_video_info);
            if (new_video_info[1] != undefined){
                var new_buttons = new_video_info[1].getElementsByClassName('style-scope ytd-segmented-like-dislike-button-renderer');
                //ez check for actually on a video
                if (new_buttons[1] != undefined){
                    var likeButt = new_buttons[1].getElementsByTagName('yt-icon')[0];
                    var dislikeButt = new_buttons[3].getElementsByTagName('yt-icon')[0];
                    likeButt.setAttribute('style', 'color: green;');
                    dislikeButt.setAttribute('style', 'color: red;');
                }
                return;
            }
        }
    }
    function set_join_buttons(){
        var joinDivs = document.querySelectorAll('#sponsor-button');
        for (var jb = 0; jb < joinDivs.length; jb++){
            var joinButton = joinDivs[jb].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 (var pb = 0; pb < joinDivs.length; pb++){
            var purchaseButton = joinDivs[pb].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(){
        var reply_info = document.getElementsByTagName('yt-formatted-string');
        //console.log(reply_info.length);
        if (reply_info.length != 0){
            for(var r = 0; r < reply_info.length; r++){
                var 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 newSubButton(){
        var subDivs = document.querySelectorAll('#subscribe-button');
        for (var sb = 0; sb < subDivs.length; sb++){
            var subButton = subDivs[sb].getElementsByTagName('button')[0];
            // console.log(subButton);
            if (subButton != undefined){
                subButton.setAttribute('id', 'oytSub');
                if (subButton.getAttribute('aria-label').toLowerCase().includes('unsubscribe')){
                    subButton.setAttribute('oytUSB', '');
                } else{
                    subButton.removeAttribute('oytUSB');
                }
            }
        }
    }
    function set_video_inf(){
        set_video_buttons();
        // set_buttons_text();
        // setSubJoin();
        newSubButton();
        set_join_buttons();
    }
    function addGlobalStyle(css) {
        var 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);
    }
    var style = '';
    //sub button; new YT ver
    style += '#oytSub{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: 25px; font-family: Arial, sans-serif; font-size: 12px;}';
    style += '#oytSub:hover{background: linear-gradient(180deg, #fffffa 0%, #fed925 100%) !important; text-decoration: underline;}';
    style += '#oytSub[oytUSB]{background: linear-gradient(180deg, #fefefe 0%, #c2c2c2 100%) !important; color: #333 !important; border: 1px solid #ccc !important;}';
    style += '#oytSub[oytUSB]:hover { background: linear-gradient(180deg, #fefefe 0%, #a8a6a6 100%) !important; }';
    //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;}';
    //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;}')
    addGlobalStyle(style);
    //we don't use the event that gets passed here since we don't need it for this script
    function evtListen(event){
        locationChange();
    }
    //this bit of script was taken and modified from the script "Youtube: Download Video" by HayaoGai
    //link to that script: https://gf.qytechs.cn/en/scripts/404304-youtube-download-video
    function locationChange() {
        //console.log('Switched page!');
        const observer = new MutationObserver(mutations => {
            set_video_inf();
        });
        const target = document.body;
        const config = { childList: true, subtree: true };
        observer.observe(target, config);
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址