Bilibili Bangumi Cover

Show Bilibili Bangumi Cover

As of 2017-01-13. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Bilibili Bangumi Cover
// @name:zh-CN   哔哩哔哩(bilibili.com)番剧封面
// @name:ja      Bilibili
// @namespace    hoothin
// @version      0.5
// @description        Show Bilibili Bangumi Cover
// @description:zh-CN  在哔哩哔哩番剧页面中显示封面
// @description:ja     Show Bilibili Bangumi Cover
// @grant        GM_xmlhttpRequest
// @author       hoothin
// @include      http*://bangumi.bilibili.com/anime/*
// ==/UserScript==

(function() {
    'use strict';
    var vSmall=document.querySelector(".recom");
    if(!vSmall)return;
    var title=document.createElement("h3");
    title.id="coverTitle";
    title.classList.add("v1-bangumi-head-h3");
    title.style.display="block";
    title.innerHTML="封面";
    var coverLink=document.createElement("a");
    var cover=document.createElement("img");
    cover.style.width="270px";
    coverLink.target="_blank";
    coverLink.appendChild(cover);
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    var observer = new MutationObserver(function(records){
        if(!vSmall.querySelector("h3#coverTitle")){
            vSmall.insertBefore(coverLink,vSmall.firstChild);
            vSmall.insertBefore(title,vSmall.firstChild);
            refreshCover();
        }
    });
    var option = {
        'childList': true
    };
    observer.observe(vSmall, option);
    function refreshCover(){
        GM_xmlhttpRequest({
            method: 'GET',
            url: bangumiIndex.href,
            onload: function(result) {
                var doc = null;
                try {
                    doc = document.implementation.createHTMLDocument('');
                    doc.documentElement.innerHTML = result.responseText;
                }
                catch (e) {
                    console.log(e);
                }
                if (!doc) {
                    return;
                }
                var img=doc.querySelector("a.v1-complete-text[href='"+location.href.replace(/https?:/,"")+"']>div>img");
                if(img){
                    coverLink.href=cover.src=img.getAttribute("src").replace(/\d+_\d+|_\d+x\d+\.jpg/,"");
                }
            }
        });
    }
    var bangumiIndex=document.querySelector(".v1-bangumi-info-title>a");
    if(bangumiIndex){
        refreshCover();
    }
})();