Give me AV not BV

F**king Bilibili, give my av number back!

目前為 2020-03-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Give me AV not BV
// @namespace    https://xsky123.com
// @version      0.1
// @description  F**king Bilibili, give my av number back!
// @author       XSky123
// @require      https://unpkg.com/[email protected]/dist/ajaxhook.min.js
// @match        https://www.bilibili.com/video/*
// @match        https://acg.tv/*
// @match        https://b23.tv/*
// @grant        none
// ==/UserScript==

if(window.location.href.match(/.*bilibili.com\/video\/BV.*/)){
    var url = "https://www.bilibili.com/video/av"+window.__INITIAL_STATE__.aid;
    window.location.href=url;
    console.log("F**k You BV Number!");
}
var is_finished_ajax = false;
var is_av_number_written = false;
ah.proxy({
    //请求发起前进入
    onRequest: (config, handler) => {
        if(config.url.indexOf("first_video_frame_decoded")!=-1){
        //console.log(config.url)
            is_finished_ajax = true;
        }
        handler.next(config);
    },

    //请求成功后进入
    onResponse: (response, handler) => {
        //console.log(response.response)
        if(is_finished_ajax && !is_av_number_written){
            document.getElementsByClassName("video-data")[0].innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<span>av"+window.__INITIAL_STATE__.aid+"</span>";
            is_av_number_written = true;
        }
        handler.next(response)
    }
})