YouTube Helper

Quality of life changes to YouTube

当前为 2025-02-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Helper
// @namespace    ccn0
// @version      7
// @description  Quality of life changes to YouTube
// @author       CCN0
// @license      MIT
// @match        *://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com&sz=64
// @grant        none
// ==/UserScript==

(function() {
    function youTubeHelper() {
        /* make player have sharp corners */
        if (document.querySelector('ytd-player')) {
            document.querySelector('ytd-player').style.borderRadius = "0";
        };
        /* make notifications badge white */
        if (document.querySelector('.yt-spec-icon-badge-shape__badge')) {
            document.querySelector('.yt-spec-icon-badge-shape__badge').style.color = "#fff";
        };
        /* hides notification amount in tab title */
        document.title = document.title.replace(/^\([0-9]*\)\s/, "");

        function removeElements(selector) {
            const elements = document.querySelectorAll(selector);
            elements.forEach(element => {
                element.remove();
            });
        };

        removeElements('button[aria-label="Search with your voice"]');
        removeElements('button[aria-label="Thanks"]');
        removeElements('button[aria-label="Join this channel"]');
        removeElements('ytd-video-description-infocards-section-renderer');
        removeElements('a.yt-simple-endpoint.style-scope.yt-formatted-string.bold');
        removeElements('a.yt-simple-endpoint.bold.style-scope.yt-formatted-string');
        removeElements('.ytd-watch-info-text>a');
        removeElements('button:has([aria-label="Channel watermark"])');
        removeElements('ytd-rich-section-renderer');
        removeElements('ytd-reel-shelf-renderer');

        /* makes links not go through youtube */
        document.querySelectorAll('a[href*="://www.youtube.com/redirect?"]').forEach(link => {
            if (link.getAttribute('href')) {
                const urlParams = new URLSearchParams(link.getAttribute('href'));
                const qParam = decodeURIComponent(urlParams.get('q'));

                if (qParam) {
                    link.setAttribute('href', qParam);
                }
            }
        });

        const shareUrlInput = document.getElementById('share-url');
        if (shareUrlInput) {
            let currentUrl = shareUrlInput.value;
            currentUrl = currentUrl.replace(/(\?|\&)si=[^&]*/g, '');
            shareUrlInput.value = currentUrl;
        };

        if (window.location.href.includes('shorts/')) {
            let noshortsurl = window.location.href.replace('shorts/', 'watch?v=');
            window.location.href = noshortsurl;
        };
    };
    setInterval(youTubeHelper, 500);
})();