Greasy Fork

Greasy Fork is available in English.

B站视频封面查看

在播放窗口下方添加查看封面的按钮

当前为 2020-06-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         B站视频封面查看
// @namespace    limgmk/bilibili-cover
// @version      0.0.2
// @description  在播放窗口下方添加查看封面的按钮
// @author       Limgmk
// @include     http*://www.bilibili.com/video/av*
// @include     http*://www.bilibili.com/video/BV*
// @run-at      document-end
// ==/UserScript==

(function() {
    'use strict';

    addNode();

    function addNode(){
        var share = document.evaluate('//span[@title="分享"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        var ops = document.evaluate('//div[@class="ops"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
        if(share.innerText != "--" && ops){

            var showCover = document.createElement("span");
            showCover.setAttribute("id", "CoverByLimgmk")

            var text = `<flag style="font-size: 20px;">🔎</flag><a style="color: #505050"> 封面</a>`
            showCover.innerHTML = text;

            showCover.addEventListener('click',function(e){
                var cover = document.evaluate('//meta[@itemprop="image" and @data-vue-meta="true"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
                if(cover){
                    var coverURL = cover.getAttribute("content");
                    coverURL = coverURL.replace(/http[s]?\:/,'');
                    window.open(coverURL, '_blank');
                }else{
                    alert("不好意思, 找不到封面链接 (゚´Д`゚)゚")
                }
            });

            showCover.addEventListener('mouseover',function(e){
                var coverLink = document.evaluate('//span[@id="CoverByLimgmk"]//a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
                coverLink.setAttribute("style", "color: 0000cc");
            });

            showCover.addEventListener('mouseout',function(e){
                var coverLink = document.evaluate('//span[@id="CoverByLimgmk"]//a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
                coverLink.setAttribute("style", "color: #505050");
            });

            share.setAttribute("style", "width: 92px;");

            ops.insertBefore(showCover, null);

        }else{
            setTimeout(addNode,100);
        }
    }

})();