Show Youtube Thumbnails

Show thumbnails in deprecated Youtube layout

目前為 2020-03-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Show Youtube Thumbnails
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Show thumbnails in deprecated Youtube layout
// @author       Kronzky
// @match        *://www.youtube.com/*
// @grant        none
// ==/UserScript==

function addThumbs() {
    var thumburl = 'https://i.ytimg.com/vi/THUMBNAIL/hqdefault.jpg';
    var thumbimg = '<div style="width:196px; height:110px; overflow:hidden"><a href="/watch?v=THUMBNAIL"><img style="position:relative; top:-19px" width="198px" src="' + thumburl + '"></a></div>';

    var items = document.getElementsByClassName('yt-lockup');
    for (var i=0; i<items.length-1; i++) {
        if ((items[i].className.indexOf("HASTHUMB"))==-1) {
            var img = items[i].getElementsByTagName("img");
            if (img.length==0) {
                var id;
                if (items[i].hasAttribute("data-context-item-id")) {
                    id = items[i].getAttribute("data-context-item-id");
                    items[i].innerHTML = thumbimg.replace(/THUMBNAIL/g, id) + items[i].innerHTML;
                } else {
                    var link = items[i].getElementsByTagName("a")[0];
                    link = link.getAttribute("href");
                    link = link.substr(link.indexOf("?v=")+3);
                    var thumb = thumbimg.replace("THUMBNAIL", link) + items[i].innerHTML;
                    id = link.substr(0,link.indexOf("&"));
                    items[i].innerHTML = thumb.replace("THUMBNAIL", id) + items[i].innerHTML;
                };
            };
            items[i].className += " HASTHUMB";
        };
    };
};

(function() {
    'use strict';
    document.cookie = 'PREF=f5=30030&f6=8&f1=50000000';
    addThumbs();
    window.addEventListener("scroll", addThumbs, false);
})();