bilibili HTML5播放器

启用bilibili的html5播放器,自动宽屏、原生右键菜单

  1. // ==UserScript==
  2. // @name bilibili HTML5播放器
  3. // @author nanavao
  4. // @namespace nana_vao_script
  5. // @description 启用bilibili的html5播放器,自动宽屏、原生右键菜单
  6. // @version 1.23
  7. // @include http://www.bilibili.com/video/av*
  8. // @include http://bangumi.bilibili.com/anime/v/*
  9. // @run-at document-start
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_deleteValue
  13. // ==/UserScript==
  14. 'use strict';
  15. (function () {
  16. let url = GM_getValue('url');
  17. GM_deleteValue('url');
  18. if (location.hostname == 'bangumi.bilibili.com') {
  19. if(url === location.href){
  20. return;
  21. }
  22. GM_setValue('url', location.href);
  23. document.addEventListener('DOMContentLoaded', function () {
  24. window.stop();
  25. location.href = document.querySelector('.v-av-link').href;
  26. });
  27. } else {
  28. try{
  29. localStorage.setItem('bilibililover', 'YESYESYES');
  30. localStorage.setItem('defaulth5', '1');
  31. }catch(e){}
  32. window.addEventListener('load', function () {
  33. this.$ = unsafeWindow.jQuery;
  34. $('.bilibili-player-video-btn-widescreen').click();
  35. scrollToPlayer();
  36. let intervalId = setInterval(function(){
  37. if($('.bilibili-player-video-wrap video').length){
  38. setContextMenuHandler();
  39. clearInterval(intervalId);
  40. }
  41. },500);
  42. });
  43. }
  44. function scrollToPlayer(){
  45. var player = $('#bilibiliPlayer');
  46. if($(window).scrollTop() === 0){
  47. $(window).scrollTop(player.offset().top + player.height() - $(window).height());
  48. }
  49. }
  50. function setContextMenuHandler(){
  51. let contextMenuEvent = $._data( document.querySelector('.bilibili-player-video-wrap'), "events" ).contextmenu[0];
  52. let oldHandler = contextMenuEvent.handler;
  53.  
  54. let isElementClicked = function(ele, x, y){
  55. let rect = ele.getBoundingClientRect();
  56. return ((x > rect.left) && (x < rect.right) && (y > rect.top) && (y < rect.bottom));
  57. };
  58.  
  59. let anyElementClicked = function(arr,x,y){
  60. for(let i = 0;i < arr.length; i++){
  61. if(isElementClicked(arr[i],x,y)){
  62. return true;
  63. }
  64. }
  65. return false;
  66. };
  67.  
  68. let newHandler = function(e){
  69. let eleArr = document.querySelectorAll('.bilibili-danmaku');
  70. if(anyElementClicked(eleArr,e.clientX,e.clientY)){
  71. oldHandler(e);
  72. }
  73. };
  74.  
  75. contextMenuEvent.handler = exportFunction(newHandler,contextMenuEvent);
  76. }
  77. }) ();

QingJ © 2025

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