Bilibili Bangumi Cover

Show Bilibili Bangumi Cover

目前為 2017-01-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bilibili Bangumi Cover
// @name:zh-CN   哔哩哔哩(bilibili.com)番剧封面
// @namespace    hoothin
// @version      0.3
// @description        Show Bilibili Bangumi Cover
// @description:zh-CN  在哔哩哔哩番剧页面中显示封面
// @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+"']>div>img");
                if(img){
                    coverLink.href=cover.src=img.src.replace(/\d+_\d+|_\d+x\d+\.jpg/,"");
                }
            }
        });
    }
    var bangumiIndex=document.querySelector(".v1-bangumi-info-title>a");
    if(bangumiIndex){
        refreshCover();
    }
})();