Get YouTube Thumbnail

Adds button to view largest thumbnail image for any video

目前為 2018-03-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            Get YouTube Thumbnail
// @version         0.6
// @description     Adds button to view largest thumbnail image for any video
// @author          Drazen Bjelovuk
// @match           *://www.youtube.com/*
// @grant           none
// @run-at          document-end
// @namespace       https://greasyfork.org/users/11679
// @contributionURL https://goo.gl/dYIygm
// ==/UserScript==

document.addEventListener('spfdone', addThumbnailButton);
document.addEventListener('yt-navigate-start', addThumbnailButton);

addThumbnailButton();

const sizes = ['/maxresdefault.jpg', '/hqdefault.jpg', '/mqdefault.jpg', '/sddefault.jpg'];
var vidId;

function tryLoad(index) {
    var image = new Image();
    image.onload = function(img) {
        if (img.path[0].naturalWidth > 120) {
            window.open(img.path[0].src);
        }
        else if (index < sizes.length - 1) {
            tryLoad(index + 1);
        }
    };
    image.src = 'https://img.youtube.com/vi/'+ vidId + sizes[index];
}

var interval;

function addThumbnailButton() {
    var button = document.getElementById('viewThumbnailBtn');
    if (button) button.remove();

    var subscribeButton = document.querySelector('ytd-video-secondary-info-renderer #subscribe-button');
    if (subscribeButton) {
        button = document.createElement('paper-button');
        button.id = 'viewThumbnailBtn';
        button.className = 'style-scope ytd-subscribe-button-renderer';
        button.style.cssText = 'margin-left: auto';
        button.textContent = 'View Thumbnail';
        button.onclick = function() {
            vidId = document.querySelector('ytd-watch').getAttribute('video-id');
            tryLoad(0);
        };
        subscribeButton.parentNode.insertBefore(button, subscribeButton);
        clearInterval(interval);
    }
    else if (~window.location.href.indexOf('v=')) {
        interval = setInterval(addThumbnailButton, 500);
    }
}