YoutTube Thumbnail Image Resolution Selector with Buttons

Add buttons for all resolutions when retrieving YouTube thumbnail images

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YoutTube Thumbnail Image Resolution Selector with Buttons
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Add buttons for all resolutions when retrieving YouTube thumbnail images
// @author       satandidnowrong
// @match        https://i.ytimg.com/*
// @grant        none
// @license      Creative Commons Attribution-NonCommercial 4.0 International License
// ==/UserScript==

(function() {
    'use strict';
    const parts = window.location.pathname.split('/');
    const newX = 'vi';
    const newY = parts[2];

    const resolutions = [
        "maxresdefault.jpg",
        "sddefault.jpg",
        "hqdefault.jpg",
        "mqdefault.jpg",
        "default.jpg",
        "hq720.jpg"
    ];

    const buttonsContainer = document.createElement('div');
    buttonsContainer.style.position = 'fixed';
    buttonsContainer.style.top = '10px';
    buttonsContainer.style.left = '10px';
    document.body.appendChild(buttonsContainer);

    resolutions.forEach(resolution => {
        const button = document.createElement('button');
        button.textContent = resolution.split('.')[0].toUpperCase();
        button.onclick = () => {
            const newUrl = `https://i.ytimg.com/${newX}/${newY}/${resolution}`;
            window.location.href = newUrl;
        };
        buttonsContainer.appendChild(button);
    });
})();