Calm Down YouTube

Converts titles on YouTube to be less obnoxious.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
})();