// ==UserScript==
// @name BilibiliCover
// @version 1.5.10
// @description B站显示视频封面
// @author AnnAngela
// @namespace https://greasyfork.org/users/129402
// @mainpage https://greasyfork.org/zh-CN/scripts/33411-bilibilicover
// @supportURL https://greasyfork.org/zh-CN/scripts/33411-bilibilicover/feedback
// @license GNU General Public License v3.0 or later
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @match *://www.bilibili.com/video/av*
// @match *://www.bilibili.com/watchlater*
// @match *://www.bilibili.com/bangumi/play/*
// @run-at document-start
// @grant unsafeWindow
// @noframes
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAC4jAAAuIwF4pT92AAAIVklEQVR4Xu2bWYwVRRSGzyzIBYwbAmpwFzPigqCi0ZgoJooa3GKMGBg3VMAIcY3xQREFNW5xfXAF1AiKPrhEURl3E6O4srggojCCIIIgIuIM/t+cauZ6p293j3jDZZiHL5lkpk7956/q6upTNdbY2GgNDQ1bLHbjZ0tszKc/Z6FC7CmOF0PEKHGxOEv0F9uL6gxxNpbq0Ff/0PclYrQYOsa1obEiQ5wmrGrSbKuaOCsLlWKAuFNME3PFR2KquEzsJXKiIkOs/0pF6GOv0Cd9zxDzxGtVrg2NlRliNWE2cbbZhFlpdBX7i9FiuvhW/CrqxUwxWVwpjhPdRHWGmK2lOsQ+LvQ1JfT9k1gu5oo3zDWitWuGmJkN2FecKR4Vv4h1okH8HX5eKD4QY0SNyImKDHGzUhFi1oQ+6Ks+9I2GhvDzUnONaN03Q9zMBtDx2WKCuduNBawUC8SL4mr7f2dC/sgT+4XQ10prqYNZOdFca02G2K0yYHAIHmdANBMYlffFjaK3bfxMiEa+d4hJ7IXWPAPjDJgkzhH7ZYif2YAe4lBxg/gydPRXjABG5UfzmXCVGCC6m49ia42oDm0HhFgvhthxI48WNKENjWjdKUMfmQ1ATGfzqfWy+E6ssZZCmAmIYZTeNR+1g0Qn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kED0xon0bSIrgq9H1OQvuSG3CSeNZ8MfrNml9T1OQRx6FEr4T2afQKMVjtqe6sDfFXhD6nipMT2pfcAEZ3uHjCvJzO7RE2KhRSKLVxENEjoX0aHI+fHmIRc5k1b4Q47OAYLOktU3IDEEgJijM9NiXTjDLThFl3mVeRKFN1SWifRpcQAxP4rH1NUMKj9jc89N09oX3JDciZf3NTi+MjhV0Z9bjDzYsR21rWc/p4qkOMPcQRIf7A0FdN6DuX0L7kBpQ77QZYuwHtBrQbYO0GJBvAD8XK4rzPqbuV82lQMdCMdnKIS35DWTz/vm3hH90ndrPkd225guZdzXOIM8DvC8gAPirYX8cZQN2NTQ3Xz9Lu+JULaOxgfj7Y37xeGTf6HI0tw4ComBlnwNvmV09PNN9y5qy8TYgOR/n+QPP15jnEGcCB8BwMqDO/MRF3PD5fvBkCsRWl/r+LubvlCNr4gjzSfODQTg6FeZErN2KmY8C95kfIcRck+Oz8wbwkzSnrQ+JB8UCZgjYucaKVuwFoJ4c4A8j5HgzggIHS1Rorvhi2FaIrdH+a5zwMA/ik5NSFqbLc2v4lqWhWk3M/DNjK/PLgW+ZrAe60tZkQjTwVpXnmCyOnSk3X5DiAPMy8ukJl53trezOBXBh5ZjnrA7nyimy6KMnrgyvmrKJUdurMy1vR3eD8jVKxHWO5kK8RzX4LxHNh1eetwP8UkKtfq7fmy9KUn/hXk1rzQiQFR1ZKZgT7hCy3wzc1Ubl8tbnmeeY5kAs5nWs+28mVnM1yT8yx3KTZERWiWhwqLhL3ijoxSywWK8TvYnWZgjY0LhIzxfSc50Au5ERu5LghZxv3xVIb9/mSfCrFzqKvOEEMFcPFFeIacW2Zg8bLx7lmtJMDuZATuf0rX1u/fr3xD9RbKu0GYMCWzD+zDS/KNPfarwAAAABJRU5ErkJggg==
// ==/UserScript==
unsafeWindow.addEventListener("load", function() {
(function loop() {
var doc = unsafeWindow.document;
var LF = String.fromCharCode(10), XX = String.fromCharCode(47);
var plw = doc.querySelector(".player-wrapper, .video-box-module > .bili-wrapper");
if (!plw) return setTimeout(loop, 1e3);
var oP = doc.createElement("p"), styles = {
width:"100px",
height:"100px",
overflowY:"scroll"
}, i, sbw;
for (i in styles) oP.style[i] = styles[i];
doc.body.appendChild(oP);
sbw = oP.offsetWidth - oP.clientWidth;
oP.remove();
function coverImage(url) {
/* 本函数来自 https://greasyfork.org/zh-CN/scripts/30714-获取哔哩哔哩视频的封面图片-get-bilibili-cover-image/code?version=202372 特此感谢*/
var coverImageBigUrl = url;
// 去除url中的裁剪标识
if (url.indexOf("@") > -1) {
//处理以@做裁剪标识的url
coverImageBigUrl = url.split("@")[0];
}
if (url.indexOf("jpg_") > -1) {
//处理以_做裁剪标识的url
coverImageBigUrl = url.split("jpg_")[0] + "jpg";
}
if (url.indexOf("png_") > -1) {
//处理以_做裁剪标识的url
coverImageBigUrl = url.split("png_")[0] + "png";
}
if (url.indexOf("/320_200/") > -1) {
//有时裁剪标识是在后缀名之前的 目前主要发现的是“番剧”板块的列表里有,但尚不清楚其他地方的情况
coverImageBigUrl = url.replace("/320_200", "");
}
if (coverImageBigUrl.substring(0, 2) === XX + XX) coverImageBigUrl = "https:" + coverImageBigUrl; else if (coverImageBigUrl.substring(0, 5) === "http:") coverImageBigUrl = coverImageBigUrl.replace("http:", "https:");
return coverImageBigUrl;
}
function getRealWidthAndHeight(src, callback) {
var imgtemp = new Image();
imgtemp.src = src;
imgtemp.addEventListener("load", function() {
callback({
width:imgtemp.width,
height:imgtemp.height
});
});
}
var img;
img = doc.createElement("img");
img.id = "cover_img";
setInterval(function() {
try {
doc.querySelector("#cover_img").src = coverImage(doc.querySelector(".cover_image, .bilibili-player-auxiliary-area .bilibili-player-watchlater-item[data-state-play=true] .bilibili-player-watchlater-cover-cell img, .bangumi-info-wrapper .info-cover img").src);
} catch (_) {
console.info("bilibiliCover", "no img");
}
}, 1e3);
plw.appendChild(img);
img.style.display = "block";
img.style.position = "absolute";
img.style.cursor = "pointer";
function calc() {
var flag = true;
var bsn = Array.from(plw.children).filter(function(ele, i) {
return plw.children[i - 1] && ele.nodeName !== "IMG" && (plw.children[i - 1].id === "bofqi" || /scontent|player-content|bangumi-player/i.test(plw.children[i - 1].classList.value));
})[0];
if (!bsn) {
bsn = plw.querySelector(".scontent, .player-content, .bangumi-player");
flag = false;
}
var ofs = getComputedStyle(bsn);
var ofl = parseInt(ofs.width) + parseInt(ofs.marginLeft) + parseInt(ofs.paddingLeft) + parseInt(ofs.borderLeftWidth), ofb = flag ? parseInt(ofs.height) + parseInt(ofs.marginTop) + parseInt(ofs.paddingTop) + parseInt(ofs.borderTopWidth) :parseInt(getComputedStyle(doc.querySelector("#bofqi")).marginBottom), wdt = ofs.width;
var w = window.innerWidth || doc.docElement.clientWidth || doc.body.clientWidth;
img.style.left = "calc(" + ofl + "px + 1em)";
img.style.bottom = "calc(" + ofb + "px + 1em)";
img.style.width = "calc(" + w + "px / 2 - " + wdt + " / 2 - 2em - " + sbw / 2 + "px)";
}
calc();
img.title = "此处是本视频封面大图!" + LF + LF + "右键菜单可复制图片大图地址," + LF + "左键单击可在新窗口查看大图!";
window.addEventListener("resize", function() {
calc();
});
window.openWin = undefined;
img.addEventListener("click", function() {
var w = window.innerWidth || doc.docElement.clientWidth || doc.body.clientWidth;
var h = window.innerHeight || doc.docElement.clientHeight || doc.body.clientHeight;
var src = this.src;
setTimeout(function() {
if (!openWin) {
openWin = window.open("about:blank", "bilibiliCover", "location=1,scrollbars=1,channelmode=1,width=" + w * .8 + ",height=" + h * .95 + ",left=" + w * .1 + ",top=" + h * .1);
setTimeout(function() {
openWin.document.body.innerHTML = '<div style="text-align: start;">视频封面地址:</div><textarea readonly="readonly" style="width: 100%; height: 1.1em; font-size: 24px; box-sizing: content-box; overflow: hidden; background-color: white; color: initial;"></textarea><hr><img src="' + src + '" style="max-width: 100%; height: auto;"><p id="realsize" style="text-align: center;"></p>';
openWin.document.body.innerHTML += '<style> a { cursor: pointer; background-position: center right;background-repeat: no-repeat;background-image: -webkit-linear-gradient(transparent, transparent), url(data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%3E%3Cg%20transform%3D%22translate%28-826.429%20-698.791%29%22%3E%3Crect%20width%3D%225.982%22%20height%3D%225.982%22%20x%3D%22826.929%22%20y%3D%22702.309%22%20fill%3D%22%23fff%22%20stroke%3D%22%2306c%22%2F%3E%3Cg%3E%3Cpath%20d%3D%22M831.194%20698.791h5.234v5.391l-1.571%201.545-1.31-1.31-2.725%202.725-2.689-2.689%202.808-2.808-1.311-1.311z%22%20fill%3D%22%2306f%22%2F%3E%3Cpath%20d%3D%22M835.424%20699.795l.022%204.885-1.817-1.817-2.881%202.881-1.228-1.228%202.881-2.881-1.851-1.851z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E); background-image: linear-gradient(transparent, transparent), url(data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%3E%3Cg%20transform%3D%22translate%28-826.429%20-698.791%29%22%3E%3Crect%20width%3D%225.982%22%20height%3D%225.982%22%20x%3D%22826.929%22%20y%3D%22702.309%22%20fill%3D%22%23fff%22%20stroke%3D%22%2306c%22%2F%3E%3Cg%3E%3Cpath%20d%3D%22M831.194%20698.791h5.234v5.391l-1.571%201.545-1.31-1.31-2.725%202.725-2.689-2.689%202.808-2.808-1.311-1.311z%22%20fill%3D%22%2306f%22%2F%3E%3Cpath%20d%3D%22M835.424%20699.795l.022%204.885-1.817-1.817-2.881%202.881-1.228-1.228%202.881-2.881-1.851-1.851z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E); padding-right: 13px; } </style>';
openWin.document.body.innerHTML += '<p style="display: flex; flex-wrap: nowrap; justify-content: space-around;"><a target="_blank" data-href="https://image.baidu.com/pcdutu?queryImageUrl=%s">Baidu识图搜索</a><a target="_blank" data-href="https://www.google.com/searchbyimage?image_url=%s&encoded_image=&image_content=&filename=&hl=zh-CN">Google识图搜索</a></p>';
openWin.document.body.style.textAlign = "center";
getRealWidthAndHeight(src, function(data) {
openWin.document.querySelector("#realsize").innerText = "(" + data.width + "×" + data.height + ")";
openWin.focus();
});
openWin.document.title = "BilibiliCover";
var t = openWin.document.querySelector("textarea");
t.value = src;
t.addEventListener("mouseup", function(e) {
if (e.which !== 1) return;
var selection = getSelection();
if (selection.toString() !== "") return;
this.focus();
this.select();
});
Array.from(openWin.document.querySelectorAll("a")).forEach(function(ele) {
ele.addEventListener("click", function() {
window.open(ele.dataset.href.replace("%s", encodeURIComponent(openWin.document.querySelector("textarea").value)), "_blank").focus();
});
});
openWin.addEventListener("beforeunload", function() {
openWin = undefined;
});
}, 0);
} else if (openWin.document.querySelector("img").src === src) openWin.focus(); else {
openWin.document.querySelector("img").src = src;
openWin.document.querySelector("textarea").value = src;
getRealWidthAndHeight(src, function(data) {
openWin.document.querySelector("#realsize").innerText = "(" + data.width + "×" + data.height + ")";
openWin.focus();
});
}
}, 0);
});
window.addEventListener("beforeunload", function() {
if (openWin) openWin.close();
});
})();
});