m.YouTube.com seek buttons

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

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

  1. // ==UserScript==
  2. // @name m.YouTube.com seek buttons
  3. // @namespace m-youtube-com-seek-buttons
  4. // @version 1.2
  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.style.margin = "5px";
  23. button.style.padding = "5px";
  24. button.style.backgroundColor = "purple";
  25. button.style.position = "relative";
  26. button.onclick = function() {
  27. let video = document.querySelector("video");
  28. if(video && video.readyState >= 2) {
  29. video.currentTime += parseInt(this.textContent.replace("s",""));
  30. }
  31. };
  32. let target = document.getElementById("seekbuttons");
  33. target.insertBefore(button, target.firstChild);
  34. }); // end times foreach
  35. } // end addbuttons
  36. // Periodically check if the buttons are visible
  37. // (sometimes YouTube redraws its interface).
  38. setInterval(()=>{
  39. // Creating a div that will contain buttons.
  40. if( document.getElementById("seekbuttons") == undefined ){
  41. let parent = document.querySelector('.related-chips-slot-wrapper'); // placement of buttons
  42. let wrapper = document.createElement('div');
  43. wrapper.setAttribute("id","seekbuttons");
  44. parent.insertBefore(wrapper, parent.firstChild);
  45. addbuttons();
  46. }
  47. }, 1000);
  48.  
  49. })();