m.YouTube.com seek buttons

Adds +-30sec +-1min +-5min buttons below the video

当前为 2023-10-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name m.YouTube.com seek buttons
  3. // @namespace m-youtube-com-seek-buttons
  4. // @version 1.1
  5. // @description Adds +-30sec +-1min +-5min buttons below the video
  6. // @author hlorand.hu
  7. // @match https://m.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  9. // @grant none
  10. // @license https://creativecommons.org/licenses/by-nc-sa/4.0/
  11. // ==/UserScript==
  12.  
  13. // Screenshot: https://ibb.co/72YKQPn
  14. (function() {
  15. //'use strict';
  16. function addbuttons(){
  17. document.getElementById("seekbuttons").innerHTML = "";
  18. const times = ["+300s", "+60s", "+30s", "-30s", "-60s", "-300s"];
  19. times.forEach((time)=>{
  20. let button = document.createElement('button');
  21. button.textContent = time;
  22. button.className = "speedbutton";
  23. button.style.margin = "5px";
  24. button.style.padding = "5px";
  25. button.style.backgroundColor = "purple";
  26. button.style.position = "relative";
  27. button.onclick = function() {
  28. let video = document.querySelector("video");
  29. if(video && video.readyState >= 2) {
  30. video.currentTime += parseInt(this.textContent.replace("s",""));
  31. }
  32. };
  33. let target = document.getElementById("seekbuttons");
  34. target.insertBefore(button, target.firstChild);
  35. }); // end times foreach
  36. } // end addbuttons
  37. // Periodically check if the buttons are visible
  38. // (sometimes YouTube redraws its interface).
  39. setInterval(()=>{
  40. // Creating a div that will contain buttons.
  41. if( document.getElementById("seekbuttons") == undefined ){
  42. let parent = document.querySelector('.related-chips-slot-wrapper'); // placement of buttons
  43. let wrapper = document.createElement('div');
  44. wrapper.setAttribute("id","seekbuttons");
  45. parent.insertBefore(wrapper, parent.firstChild);
  46. addbuttons();
  47. }
  48. }, 1000);
  49.  
  50. })();