Skip to content

Instantly share code, notes, and snippets.

@eight04
Created March 4, 2018 12:02
Show Gist options
  • Save eight04/4165cb97a1435ca6997c74b677e36ce1 to your computer and use it in GitHub Desktop.
Save eight04/4165cb97a1435ca6997c74b677e36ce1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Bilibili Cover
// @namespace http://t.qq.com/HeartBlade
// @description 显示视频封面
// @include http://www.bilibili.com/video/av*
// @include https://www.bilibili.com/video/av*
// @version 1.3
// @grant GM_addStyle
// ==/UserScript==
var cover_box=document.createElement("div");
cover_box.id="cover_box";
var cover_image=getCoverImage();
cover_image.id="cover_image";
var cover_text=document.createElement("span");
cover_text.textContent="视频封面";
cover_text.id="cover_text";
cover_box.appendChild(cover_text);
cover_box.appendChild(cover_image);
getLiveBox().then(liveBox => liveBox.parentNode.insertBefore(cover_box, liveBox));
var css=`
.elecrank-wrapper{
padding:30px 0px 0px 10px;
}
#cover_box{
padding-left:10px;
padding-top:38px;
}
#cover_box img{
display:inline!important;
width:258px;
height:auto;
margin-top:20px;
}
#cover_text{font-size:16px}
.r-wrapper > #cover_box {
padding-bottom: 38px;
}
`;
GM_addStyle(css);
function getLiveBox() {
return new Promise(resolve => {
(function recursive() {
const liveBox = document.querySelector(".v-live-recommend, .pop-live");
if (liveBox) {
resolve(liveBox);
} else {
setTimeout(recursive, 200);
}
})();
});
}
function getCoverImage() {
const url = getUrl();
const a = document.createElement("a");
const img = new Image;
a.title = "Bilibili Cover";
a.href = url;
a.target = "_blank";
img.src = url;
a.appendChild(img);
return a;
function getUrl() {
const coverImage = document.querySelector(".cover_image");
if (coverImage) {
return coverImage.src;
}
return unsafeWindow.__INITIAL_STATE__.videoData.pic;
}
}
@eight04
Copy link
Author

eight04 commented Mar 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment