Bilibili 自动宽屏

添加一个新的「自动宽屏」按钮在 Bilibili 播放页面

  1. // ==UserScript==
  2. // @name Bilibili 自动宽屏
  3. // @name:zh-CN Bilibili 自动宽屏
  4. // @name:zh-TW Bilibili 自動寬螢幕
  5. // @name:en Bilibili Auto Wide Screen
  6. // @namespace https://github.com/Zomby7e/public-stuff/blob/master/user-script/bilibili-auto-wide-screen.user.js
  7. // @version 1.2.0
  8. // @description Bilibili Auto Wide Screen / Bilibili 播放页面自动宽屏
  9. // @description:zh-cn 添加一个新的「自动宽屏」按钮在 Bilibili 播放页面
  10. // @description:zh-tw 添加一個新的「自动宽屏」按鈕在 Bilibili 播放頁面
  11. // @description:en Add an "Auto Wide Screen" to bilibili
  12. // @match https://www.bilibili.com/video/*
  13. // @author Zomby7e
  14. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @license WTFPL
  18. // ==/UserScript==
  19.  
  20. /*
  21. * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  22. * Version 2, December 2004
  23. *
  24. * Copyright (C) 2024 Zomby7e <zomby7e@gmail.com>
  25. * Everyone is permitted to copy and distribute verbatim or modified
  26. * copies of this license document, and changing it is allowed as long
  27. * as the name is changed.
  28. *
  29. * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  30. * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  31. * 0. You just DO WHAT THE FUCK YOU WANT TO.
  32. *
  33. */
  34.  
  35. // ---- Browser storage varribles ----
  36. // isAutoWideScreen -- Defined if video page will be auto set to wide screen
  37.  
  38. // ---- Global varribles in this script ----
  39. let playerControlContainer = null; // Element, it contains the "auto wide screen mode" button
  40. let isAutoWideScreen = true; // Boolean, if not set, it will be true by default
  41. let autoWideScreenButton = document.createElement('div'); // It will be added in `playerControlContainer`, starts with "自动宽屏"
  42.  
  43. // Entry, start here
  44. (function() {
  45. 'use strict';
  46. getLocalValues();
  47. initElements();
  48. isAutoWideScreen && checkWideScreenButtonElement();
  49. checkPlayerControllerElement();
  50. customShortcutKeys();
  51. })();
  52.  
  53. // get storaged local values
  54. function getLocalValues() {
  55. isAutoWideScreen = GM_getValue('isAutoWideScreen', true);
  56. }
  57.  
  58. // Initialize all elements that needs to be inserted into the DOM
  59. function initElements(){
  60. let textContent = "自动宽屏: ";
  61. textContent += isAutoWideScreen ? '开': '关';
  62. autoWideScreenButton.textContent = textContent;
  63. autoWideScreenButton.style.color = 'hsla(0, 0%, 100%, .8)';
  64. autoWideScreenButton.style.fontFamily = '-apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif';
  65. autoWideScreenButton.style.marginRight = '2em';
  66. autoWideScreenButton.style.fontSize = '14px';
  67. autoWideScreenButton.style.fontWeight = 'bold';
  68. autoWideScreenButton.style.cursor = 'pointer';
  69. autoWideScreenButton.style.userSelect = 'none';
  70. autoWideScreenButton.style.webkitUserSelect = 'none'; // For WebKit browsers
  71. autoWideScreenButton.style.mozUserSelect = 'none'; // For Mozilla browsers
  72. autoWideScreenButton.style.msUserSelect = 'none';
  73. autoWideScreenButton.onclick = function() {
  74. isAutoWideScreen = !isAutoWideScreen;
  75. const newTextContent = isAutoWideScreen? "自动宽屏: 开": "自动宽屏: 关";
  76. autoWideScreenButton.textContent = newTextContent;
  77. GM_setValue('isAutoWideScreen', isAutoWideScreen);
  78. };
  79. }
  80.  
  81. // Get wide screen button element
  82. function checkWideScreenButtonElement() {
  83. const element = document.querySelector("div.bpx-player-ctrl-btn-icon.bpx-player-ctrl-wide-enter > span")
  84. if (element) {
  85. ChangeWideScreenMode()
  86. } else {
  87. setTimeout(checkWideScreenButtonElement, 50)
  88. }
  89. }
  90.  
  91. function ChangeWideScreenMode() {
  92. document.querySelector("div.bpx-player-ctrl-btn-icon.bpx-player-ctrl-wide-enter > span").click()
  93. }
  94.  
  95. function checkPlayerControllerElement() {
  96. const element = document.querySelector('.bpx-player-control-bottom-right')
  97. if (element) {
  98. playerControlContainer = document.querySelector('.bpx-player-control-bottom-right');
  99. addAutoWideScreenButton(playerControlContainer);
  100. } else {
  101. setTimeout(checkWideScreenButtonElement, 50)
  102. }
  103. }
  104.  
  105. // Add auto theater button
  106. function addAutoWideScreenButton(targetElement) {
  107. if (targetElement) {
  108. // Insert the new div as the first child of the target element
  109. targetElement.insertBefore(autoWideScreenButton, targetElement.firstChild);
  110. } else {
  111. console.log('Player control container not found');
  112. }
  113. }
  114.  
  115. // Enable custom shortcut keys
  116. function customShortcutKeys() {
  117. // Press "T" to change wide screen mode like youtube theater mode
  118. document.addEventListener('keydown', function(event) {
  119. // Check if the key pressed is 'T' or 't'
  120. if (event.key === 'T' || event.key === 't') {
  121. ChangeWideScreenMode();
  122. }
  123. });
  124. }

QingJ © 2025

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