CLICK TO PAUSE/PLAY

Userscript that enables pause/play on click for kick.com

目前为 2024-03-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name CLICK TO PAUSE/PLAY
  3. // @description Userscript that enables pause/play on click for kick.com
  4. // @version 7.3
  5. // @grant none
  6. // @author Trilla_G
  7. // @match *://kick.com/*
  8. // @namespace https://greasyfork.org/en/users/1200587-trilla-g
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. document.addEventListener("click", clickHandler, false);
  14.  
  15. function clickHandler(e) {
  16. // Check if the click is on the video element
  17. let player = getPlayer();
  18. if (!player || e.target !== player) {
  19. return;
  20. }
  21.  
  22. // Prevent default action
  23. e.preventDefault();
  24.  
  25. // Toggle play/pause
  26. if (player.paused) {
  27. // Video is paused, click on the big play button
  28. let playButton = getPlayButton();
  29. if (playButton) {
  30. playButton.click();
  31. setTimeout(clickMessageInput, 1500); // Delay before clicking the message input box
  32. }
  33. } else {
  34. // Video is playing, pause the video
  35. player.pause();
  36. }
  37. }
  38.  
  39. function getPlayer() {
  40. var possibleVideo = document.querySelector('.vjs-tech');
  41. if (!possibleVideo || possibleVideo.nodeName !== "VIDEO") {
  42. return null;
  43. }
  44. return possibleVideo;
  45. }
  46.  
  47. function getPlayButton() {
  48. var playButton = document.querySelector('.vjs-big-play-button');
  49. return playButton;
  50. }
  51.  
  52. function clickMessageInput() {
  53. let messageInputButton = document.querySelector('#message-input');
  54. if (messageInputButton) {
  55. messageInputButton.click();
  56. }
  57. }
  58. })();