Greasy Fork

Greasy Fork is available in English.

bilibili封面替换右侧广告

脚本将视频右侧的广告替换为视频封面

当前为 2019-10-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         bilibili封面替换右侧广告
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  脚本将视频右侧的广告替换为视频封面
// @author       You
// @match        *://www.bilibili.com/video/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    var apiurl = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword='
    function init() {
        console.log('find')
        var sidead = document.getElementsByClassName('slide-gg')[0]
        if (sidead) {
            sidead.innerHTML = '<img id="indexPIC" style="height:100%;width:100%;">'
            var pageurl = document.location.href
            var avNo = pageurl.match(/av[0-9]+/)

            var xhr = new XMLHttpRequest()
            xhr.open('GET', apiurl+avNo, true)
            xhr.onload = function () {
                if (this.status === 200) {
                    var rtx = this.responseText
                    var imgurl = rtx.match(/"pic":"(.*?)",/)[1]
                    document.getElementById('indexPIC').src=imgurl
                }
            }
            xhr.send()

        } else {
            requestAnimationFrame(function () {
                init()
            })
        }
    }
    init()
})();