Youtube removes clickbait from thumbnails

Removes clickbait from thumbnails changing to start/middle/end thumb of video

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            	Youtube removes clickbait from thumbnails
// @namespace       	https://greasyfork.org/users/821661
// @match           	https://www.youtube.com/*
// @grant           	GM_registerMenuCommand
// @grant           	GM_setValue
// @grant           	GM_getValue
// @version         	0.2
// @author          	hdyzen
// @description     	Removes clickbait from thumbnails changing to start/middle/end thumb of video
// @license         	MIT
// ==/UserScript==
'use strict';

const optionsMenu = {
    start: 'hq1',
    middle: 'hq2',
    end: 'hq3',
    default: 'hqdefault',
};

let optionSelected = GM_getValue('optionSelected', optionsMenu['start']);

const regexThumbName = /(?<=\/)hq.*(?=\.)/;

function createMenu() {
    Object.keys(optionsMenu).forEach(id => {
        let optionAtual = optionsMenu[id];
        GM_registerMenuCommand(
            `${optionAtual === optionSelected ? '[⬤]' : '[◯]'} Use thumbnail from ${id}`,
            e => {
                GM_setValue('optionSelected', optionAtual);
                optionSelected = optionAtual;
                createMenu();
                changeThumbsAfter();
            },
            { autoClose: false, id: optionAtual },
        );
    });
}

function changeThumbsAfter() {
    const thumbs = document.querySelectorAll('a#thumbnail > .ytd-thumbnail > img[src]');
    thumbs.forEach(thumb => {
        thumb.src = thumb.src.replace(regexThumbName, optionSelected);
    });
}

function changeThumbsOnInit() {
    document.addEventListener('image-loaded', e => {
        if (!e.target.src.includes(`${optionSelected}.`)) {
            e.target.src = e.target.src.replace(regexThumbName, optionSelected);
        }
    });
}

createMenu();
changeThumbsOnInit();