m.YouTube.com more playback speeds

Adds 2.25x 2.5x 2.75x 3x speed buttons below the video

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

  1. // ==UserScript==
  2. // @name m.YouTube.com more playback speeds
  3. // @namespace m-youtube-com-more-playback-speeds
  4. // @version 1.4
  5. // @description Adds 2.25x 2.5x 2.75x 3x speed 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/chtmD9F
  14.  
  15. (function() {
  16. //'use strict';
  17.  
  18. function addbuttons(){
  19. document.getElementById("speedbuttons").innerHTML = "";
  20.  
  21. const speeds = ["3.5","3.25","3.0","2.75","2.5","2.25","2.0","1.75","1.5"];
  22.  
  23. speeds.forEach((speed)=>{
  24. let button = document.createElement('button');
  25. button.textContent = speed;
  26. button.className = "speedbutton";
  27.  
  28. button.style.margin = "5px";
  29. button.style.padding = "5px";
  30. button.style.backgroundColor = "blue";
  31. button.style.position = "relative";
  32.  
  33. button.onclick = function() {
  34. let video = document.querySelector("video");
  35.  
  36. if(video && video.readyState >= 2) {
  37.  
  38. video.playbackRate = this.textContent;
  39.  
  40. video.mozPreservesPitch = video.webkitPreservesPitch = video.preservePitch = true;
  41.  
  42. // highlight the clicked button and desaturate the others
  43. document.querySelectorAll(".speedbutton").forEach((btn)=>{
  44. btn.style.backgroundColor = "blue";
  45. });
  46. this.style.backgroundColor = "darkorange";
  47. }
  48. };
  49.  
  50. let target = document.getElementById("speedbuttons");
  51. target.insertBefore(button, target.firstChild);
  52.  
  53. }); // end speeds foreach
  54.  
  55. } // end addbuttons
  56.  
  57. // Periodically check if the buttons are visible
  58. // (sometimes YouTube redraws its interface).
  59. setInterval(()=>{
  60. // Creating a div that will contain buttons.
  61. if( document.getElementById("speedbuttons") == undefined ){
  62. let parent = document.querySelector('.related-chips-slot-wrapper'); // placement of buttons
  63. let wrapper = document.createElement('div');
  64. wrapper.setAttribute("id","speedbuttons");
  65. parent.insertBefore(wrapper, parent.firstChild);
  66. addbuttons();
  67. }
  68. }, 1000);
  69.  
  70. })();