Adds button to view largest thumbnail image for any video
当前为
// ==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);
}
}