哔哩哔哩自动打开字幕(兼容自动连播)

bilibili b站 哔哩哔哩 播放视频时自动打开网站字幕(兼容自动连播)

  1. // ==UserScript==
  2. // @name 哔哩哔哩自动打开字幕(兼容自动连播)
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-07-29 0.0.2
  5. // @description bilibili b站 哔哩哔哩 播放视频时自动打开网站字幕(兼容自动连播)
  6. // @author You
  7. // @match https://www.bilibili.com/video/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let queryValue = '';
  17. // 定时检测URL是否发生变化
  18. let timer = setInterval(function() {
  19. // 获取URL中的查询字符串部分
  20. const queryString = window.location.search;
  21. // 解析查询字符串,将参数以对象的形式存储
  22. const params = new URLSearchParams(queryString);
  23. // 获取特定参数的值
  24. const value = getBilibiliVideoIdFromUrlRegex();
  25. if (queryValue !== value) {
  26. openSubtitle();
  27. queryValue = value;
  28. }
  29. }, 2000);
  30.  
  31. window.addEventListener('unload', function(_event) {
  32. clearInterval(timer)
  33. });
  34.  
  35. function getBilibiliVideoIdFromUrlRegex() {
  36. var url = window.location.href;
  37. var regex = /https:\/\/www\.bilibili\.com\/video\/(BV[a-zA-Z0-9]+)/;
  38. var match = url.match(regex);
  39.  
  40. if (match && match.length > 1) {
  41. return match[1]; // match[0] 是整个匹配的字符串,match[1] 是第一个捕获组(即BV编号)
  42. } else {
  43. return null; // 没有找到匹配项
  44. }
  45. }
  46.  
  47. function openSubtitle(){
  48. setTimeout(() => { document.querySelector('.bpx-player-ctrl-btn[aria-label="字幕"] .bpx-common-svg-icon').click(); }, 1000)
  49. }
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址