m.YouTube.com more playback speeds

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

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

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