Bilibili番剧显示单集信息

看番时让B站显示单集的的播放量和弹幕量

// ==UserScript==
// @name         Bilibili番剧显示单集信息
// @namespace    http://tampermonkey.net/
// @version      2.5
// @include     http*://www.bilibili.com/bangumi/play/ss*
// @include     http*://www.bilibili.com/bangumi/play/ep*
// @description  看番时让B站显示单集的的播放量和弹幕量
// @author       ementt
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    const url = 'https://api.bilibili.com/x/web-interface/archive/stat';
    var all_view

    var search = function() {
        var aid = 0
        var _view = $('.media-count').text().split('·')[0]
        if(!all_view){
                all_view = _view.substring(0, _view.length - 4) + '总播放'

        }

        aid = $('.av-link');

        var avid = aid.text();
        $.ajax({
            dataType: "JSONP",
            type: "get",
            data: {
                bvid: avid,
                jsonp: 'jsonp'
            },
            url: url,
            success: function(response) {
                var view = Number(response.data.view);
                var danmaku = Number(response.data.danmaku)
                var coin = Number(response.data.coin)
                var view_write = ''
                var danmu_write = ''
                if (!view) {
                    view_write = '--'
                } else if (view < 10000) {
                    view_write = view;
                } else {
                    view_write = Math.floor(view / 10000) + '万'
                }
                if (!danmaku) {
                    danmu_write = '--'
                } else if (danmaku < 10000) {
                    danmu_write = danmaku
                } else {
                    danmu_write = Math.floor(danmaku / 10000) + '万'
                }
                $("#toolbar_module > div.coin-info > span").text(coin)

                var text = `${view_write}播放  ·  ${danmu_write}弹幕  ·`
                var text2 = $('.media-count').text().split('·')[2]
                $('.media-count').text(text + text2 +'  ·  '+  all_view  )

            }
        })
    };
    var bind = function() {
        $('.av-link').bind('DOMNodeInserted', search)
    }


    setTimeout(search, 2000)
    setTimeout(bind, 2000)


})();