YouTube.com seek buttons (Mobile / Desktop)

Adds +-30sec +-1min +-5min buttons below the video. Works on mobile, tablet (m.youtube.com) and on desktop.

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