Greasy Fork is available in English.
獲取影片封面!
当前为
// ==UserScript==
// @name Youtube封面
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 獲取影片封面!
// @author Anong0u0
// @include *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="封面";
ea.id= "ytCover";
ea.target= "_blank";
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});
}