Calm Down YouTube

Converts titles on YouTube to be less obnoxious.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Calm Down YouTube
// @version      1.3
// @description  Converts titles on YouTube to be less obnoxious.
// @author       Ryan Poole
// @match        *://www.youtube.com/*
// @run-at        document-start
// @namespace https://greasyfork.org/users/48078
// ==/UserScript==

var channels = ['Hat Films', 'YOGSCAST Lewis & Simon'];

var acronyms = ['GTA', 'TTT'];

function transformTitle (title) {
    var splitTitle = /(.*?)(\((.*)\))?$/.exec(title.trim());
    var gameName = splitTitle[3];
    var videoName = splitTitle[1];
    var newName = ((gameName ? gameName.trim() + " - "  : "") + videoName.trim()).toLowerCase();
    acronyms.forEach(function(a) {
        newName = newName.replace(a.toLowerCase(), a.toUpperCase());
    });
    return newName;
}

var observer = new MutationObserver(parsePage);

function onPageLoad () {
    setupObservers();
    parsePage();
}

function setupObservers () {
    observer.disconnect();
    var elsToObserve = ['.section-list', '.branded-page-v2-body', '.channels-browse-content-grid', '#pl-load-more-destination', '#watch-more-related'];
    var el;
    elsToObserve.forEach(function(elName) {
        if ((el = document.querySelector(elName)) !== null) {
            observer.observe(el, {childList:true});
        }
    });
}

function parsePage () {
    var titleEls = [];

    var pageChannelNameEl = document.querySelector('.branded-page-header-title-link');

    function parseDOMList (opts) {
        var listSelector = opts.list || null;
        var nameSelector = opts.name || null;
        var titleSelector = opts.title || null;
        var videos = document.querySelectorAll(listSelector);
        for (var i = 0; i < videos.length; i++) {
            var currentVideoEl = videos[i];
            var currentNameEl = currentVideoEl.querySelector(nameSelector);
            var channelName = (currentNameEl !== null ? currentNameEl.textContent : null) || (pageChannelNameEl !== null ? pageChannelNameEl.text : null) || null;
            if (channelName === null) {
                continue;
            }
            if (channels.includes(channelName)) {
                titleEls.push(currentVideoEl.querySelector(titleSelector));
            }
        }
    }

    parseDOMList({
        list:'.yt-lockup-content',
        name:'.yt-lockup-byline>a',
        title:'.yt-lockup-title>a'
    });

    parseDOMList({
        list:'.lohp-media-object-content',
        name:'.content-uploader>a',
        title:'.lohp-video-link'
    });

    parseDOMList({
        list:'.pl-video',
        name:'.pl-video-owner>a',
        title:'.pl-video-title>a'
    });

    parseDOMList({
        list:'.video-list-item',
        name:'.g-hovercard',
        title:'.title'
    });

    parseDOMList({
        list:'.playlist-video',
        name:'.video-uploader-byline>span',
        title:'h4'
    });

    parseDOMList({
        list:'.video-detail',
        title:'h3>a'
    });

    parseDOMList({
        list:'.lohp-large-shelf-container',
        name:'.content-uploader>a',
        title:'.lohp-video-link'
    });

    for (i = 0; i < titleEls.length; i++) {
        var titleEl = titleEls[i];
        if (titleEl.getAttribute("data-parsed" === "true")) {
            continue;
        }
        titleEl.style.textTransform = 'capitalize';
        titleEl.setAttribute("data-parsed", true);
        titleEl.textContent = transformTitle(titleEl.textContent);
    }
}

(function() {
    'use strict';
    document.addEventListener('spfdone', onPageLoad);
    window.addEventListener('DOMContentLoaded', onPageLoad);
})();