Skip to content
On this page

B站视频播放速率插件

因为b站的视频播放最多只能2倍速观看,所以开发了这个小插件

效果示例

原始图

效果图

代码

项目结构

项目代码

// manifest.json
{
  "manifest_version": 3,
  "name": "videoPlaybackTime",
  "version": "1.0",
  "description": "B station video playback time plug-in",
  "icons": {},
  "content_scripts": [
    {
      "js": [
        "scripts/content.js"
      ],
      "matches": [
        "https://www.bilibili.com/video/*"
      ]
    }
  ]
}
javascript
// content.js
window.onload = () => {
  init()
};

function init() {
  let target = document.querySelector(".bpx-player-ctrl-playbackrate-menu");
  if (target) {
    target.setAttribute("overflow-y", "scroll");
    let list = [2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 3];
    list.forEach((item) => {
      let liEle = document.createElement("li");
      liEle.className = "bpx-player-ctrl-playbackrate-menu-item";
      liEle.setAttribute("data-value", item);
      liEle.innerText = item + "x";
      target.appendChild(liEle);
    });
  } else {
    setTimeout(() => {
      init();
    }, 1000);
  }
}