Greasy Fork

Greasy Fork is available in English.

B站封面获取

B站视频和番剧播放页添加获取封面的按钮

当前为 2020-03-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @id             BilibiliCover@Laster2800
// @name           B站封面获取
// @version        2.0
// @namespace      laster2800
// @author         Laster2800
// @description    B站视频和番剧播放页添加获取封面的按钮
// @include        *://www.bilibili.com/video/*
// @include        *://www.bilibili.com/bangumi/play/*
// @grant          GM_addStyle
// ==/UserScript==

(function() {
    var interval = 100
    var timeout = 5000
    var maxCnt = timeout / interval
    var cnt = 0
    var tid = setInterval(() => {
        var app = document.querySelector('#app')
        var vueLoad = app && app.__vue__
        if (++cnt > maxCnt) {
            clearInterval(tid)
        } else if (vueLoad) {
            clearInterval(tid)
            if (/\/video\//.test(location.href)) {
                addVideoBtn()
            } else { // /\/bangumi\/play\//.test(location.href)
                addBangumiBtn()
            }
        }
    }, interval)
})();

function addVideoBtn() {
    var atr = document.querySelector('#arc_toolbar_report')
    if (atr) {
        var coverMeta = document.querySelector('head meta[itemprop=image]')
        var coverUrl = coverMeta && coverMeta.content
        var cover = document.createElement('a')
        var errorMsg = '获取失败,若非网络问题请提供反馈'
        cover.innerText = '获取封面'
        cover.onclick = () => coverUrl ? window.open(coverUrl) : alert(errorMsg)
        cover.title = coverUrl || errorMsg
        cover.className = 'appeal-text'
        atr.appendChild(cover)
    }
}

function addBangumiBtn() {
    var tm = document.querySelector('#toolbar_module')
    if (tm) {
        GM_addStyle(`
        .cover_btn {
            float: right;
            cursor: pointer;
            font-size: 12px;
            margin-right: 16px;
            line-height: 36px;
            color: #505050;
        }
        .cover_btn:hover {
            color: #00a1d6;
        }`)
        var coverMeta = document.querySelector('head meta[property="og:image"]')
        var coverUrl = coverMeta && coverMeta.content
        var cover = document.createElement('a')
        var errorMsg = '获取失败,若非网络问题请提供反馈'
        cover.innerText = '获取封面'
        cover.onclick = () => coverUrl ? window.open(coverUrl) : alert(errorMsg)
        cover.title = coverUrl || errorMsg
        cover.className = 'cover_btn'
        tm.appendChild(cover)
    }
}