bili_上下p控制

ctl + <>键控制上一p或下一p

  1. // ==UserScript==
  2. // @name bili_上下p控制
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description ctl + <>键控制上一p或下一p
  6. // @author kakasearch
  7. // @match https://www.bilibili.com/bangumi/play/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. function FullScreen() {
  14. //全屏播放
  15. var ele = document.getElementsByTagName('video')[0]
  16. if (ele.requestFullscreen) {
  17. ele.requestFullscreen();
  18. } else if (ele.mozRequestFullScreen) {
  19. ele.mozRequestFullScreen();
  20. } else if (ele.webkitRequestFullScreen) {
  21. ele.webkitRequestFullScreen();
  22. }
  23. }
  24. function isFullscreen(){
  25. return document.fullscreenElement ||
  26. document.msFullscreenElement ||
  27. document.mozFullScreenElement ||
  28. document.webkitFullscreenElement || false;
  29. }
  30. let full_flag = 0
  31. window.document.addEventListener("keydown", function(event){
  32. var e = window.event
  33. if(isFullscreen()){full_flag=1}else{full_flag=0}
  34. if((window.event.ctrlKey)&&(window.event.keyCode==190)){//下一个视频
  35. document.querySelector("ul > li.ep-item.cursor.visited"
  36. ).nextElementSibling.click()
  37.  
  38. }else if((window.event.ctrlKey)&&(window.event.keyCode==188)){//上一个视频
  39. document.querySelector("ul > li.ep-item.cursor.visited").previousElementSibling.click()
  40. }
  41. if(full_flag){
  42. //之前是全屏播放的
  43. let obser = setInterval(
  44. function(){
  45. let video= document.querySelector("#bilibili-player video")
  46. if(video){
  47. clearInterval(obser)
  48. FullScreen()
  49. full_flag = 0
  50. }
  51.  
  52. },200
  53. )
  54. }
  55.  
  56. });
  57.  
  58. // Your code here...
  59. })();