V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kdxcxs
V2EX  ›  问与答

求助怎么用 js 打开 B 站 web 播放器的视频统计信息

  •  
  •   kdxcxs · Jan 28, 2020 · 2319 views
    This topic created in 2288 days ago, the information mentioned may be changed or developed.

    想给 B 站的 web 播放器加一个快捷键(懒癌患者).

    虽然手动打开后可以通过$('.bilibili-player-video-info-container').show()和$('.bilibili-player-video-info-container').hide()来控制,但是必须先手动打开一次,应该是初始化没有这个元素,手动打开一次后才 append 进去的.

    我也试过了在网页加载好后就用 MouseEvent 来模拟鼠标点击先初始化插入一次,但是一直没能弄出来那个右键菜单.

    恳请大佬们支支招

    4 replies    2020-01-28 19:10:01 +08:00
    jugelizi
        1
    jugelizi  
       Jan 28, 2020 via iPhone
    settimeout
    kdxcxs
        2
    kdxcxs  
    OP
       Jan 28, 2020
    @jugelizi 能麻烦详细说一下吗
    ysc3839
        3
    ysc3839  
       Jan 28, 2020   ❤️ 1
    const wrap = document.getElementsByClassName('bilibili-player-video-wrap')[0];
    wrap.dispatchEvent(new MouseEvent("contextmenu", {
    bubbles: true,
    cancelable: false,
    view: window,
    button: 2,
    buttons: 0,
    clientX: wrap.getBoundingClientRect().x,
    clientY: wrap.getBoundingClientRect().y
    }));
    const menu = document.getElementsByClassName('bilibili-player-context-menu-origin')[0];
    const a = menu.getElementsByTagName('a');
    a[a.length - 1].click();
    kdxcxs
        4
    kdxcxs  
    OP
       Jan 28, 2020
    @ysc3839 多谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1150 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:19 · PVG 01:19 · LAX 10:19 · JFK 13:19
    ♥ Do have faith in what you're doing.