youtube 封面

获取视频封面!

目前为 2021-01-14 提交的版本。查看 最新版本

// ==UserScript==
// @name               Youtube 封面
// @name:en            Youtube Cover
// @name:zh-CN         youtube 封面
// @namespace          http://tampermonkey.net/
// @version            0.1.4
// @description        獲取影片封面!
// @description:en     Get the cover of youtube video!
// @description:zh-CN  获取视频封面!
// @author             Anong0u0
// @include            *//www.youtube.com/*
// @grant              none
// ==/UserScript==


window.onload = function() {

    var elink = document.createElement("link");
    elink.rel = "stylesheet";
    elink.href = "https://cdn.jsdelivr.net/gh/chiron-fonts/[email protected]/build/webfont/css/Medium.css";
    var ea = document.createElement("a");
    ea.text = document.querySelector("html").lang.indexOf("zh")!=-1?"封面":"Cover";
    ea.id = "ytCover";
    ea.target = "_blank";
    ea.hidden = true;
    ea.style = 'text-decoration:none;font-size: 2em;font-family: "Chiron Sans HK WS";';
    document.querySelector("#start").append(elink);
    document.querySelector("#start").append(ea);

    var ytC = document.querySelector("#ytCover");
    var mas = document.querySelector("#masthead");
    var title = document.querySelector("title");
    ytC.style.color = mas.dark? "white":"black";
    var oldHref = null

    var urlChange = new MutationObserver(function(mutations)
    {
        mutations.forEach(function(mutation)
        {
            if (oldHref != document.location.href)
            {
                oldHref = document.location.href

                var video_id = null;
                window.location.search.replace("?","").split('&').forEach((s)=>{if(s.startsWith("v=")){video_id=s.replace("v=","")};});
                ytC.hidden = (video_id == null);
                ytC.href = "https://i.ytimg.com/vi/" + video_id + "/maxresdefault.jpg";
            }
        })
    });
    var darkMode = new MutationObserver(function(mutations){ytC.style.color = mas.dark? "white":"black"});

    urlChange.observe(title, {childList: true});
    darkMode.observe(mas, {attributes: true});
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址