Greasy Fork

Greasy Fork is available in English.

在视频信息区显示视频 av 号

Display avid on video information header.

当前为 2025-06-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         在视频信息区显示视频 av 号
// @namespace    im.outv.userscripts.bilibili.avid
// @version      0.1.0
// @description  Display avid on video information header.
// @author       You
// @match        https://www.bilibili.com/video/*
// @match        https://*.bilibili.com/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let avidElement;

    function createAvidElement() {
        const div = document.createElement("div")
        document.querySelector('.video-info-detail-list').appendChild(div)
        return div
    }

    function updateAvidDisplay(aid, bvid) {
        if (!aid) return
        if (!avidElement || !avidElement.isConnected) {
            avidElement = createAvidElement()
        }

        avidElement.innerText = `${bvid} av${aid}`
        console.log("Updated", aid, bvid, avidElement)
    }

    function onStateUpdate(value) {
        console.log("State updated", value)
        updateAvidDisplay(window.__INITIAL_STATE__.aid, window.__INITIAL_STATE__.bvid)

    }

    if (typeof window.__INITIAL_STATE__ === "undefined") {
      window.__INITIAL_STATE__ = {};
    }
    window.__INITIAL_STATE__ = new Proxy(window.__INITIAL_STATE__, {
        set(target, prop, value) {
            target[prop] = value;
            onStateUpdate(value);
            return true;
        }
  });
})();