Random Video For Youtube

Play Random Video in Youtube

当前为 2024-06-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Random Video For Youtube
  3. // @name:fr Video Aléatoire Pour Youtube
  4. // @name:en Random Video For Youtube Video
  5. // @namespace http://tampermonkey.net/
  6. // @author TrouveMe
  7. // @version 0.1
  8. // @description Play Random Video in Youtube
  9. // @description:fr Lance Video Aléatoire sur Youtube
  10. // @description:en Play Random Video in Youtube Video
  11. // @match https://*.youtube.com/*
  12. // @grant none
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. function getRandomInt(min, max) {
  20. return Math.floor(Math.random() * (max - min + 1)) + min;
  21. }
  22.  
  23. function clickRandomNthItem(selector) {
  24. let items = document.querySelectorAll(selector);
  25. let randomIndex = getRandomInt(0, items.length - 1);
  26. if (items[randomIndex]) {
  27. items[randomIndex].click();
  28. }
  29. }
  30.  
  31. function createButton() {
  32. const button = document.createElement('button');
  33. //button.innerText = "Lancer musique aléatoire";
  34. const imgbtn = new Image(32, 32)
  35. imgbtn.src = "https://www.svgrepo.com/show/458362/sort-random.svg"
  36. imgbtn.alt = "Picture For Random Button / Image Pour le Bouton Aléatoire"
  37. button.appendChild(imgbtn)
  38. button.style.position = 'fixed';
  39. button.style.top = '90%';
  40. button.style.right = '1.5%';
  41. button.style.zIndex = 1000;
  42. button.style.padding = '10px';
  43. button.style.backgroundColor = '#1DB954';
  44. button.style.color = '#FFFFFF';
  45. button.style.border = 'none';
  46. button.style.borderRadius = '5px';
  47. button.style.cursor = 'pointer';
  48. button.addEventListener('mouseover', () => { button.style.backgroundColor = '#1a8a41'})
  49. button.addEventListener('mouseout', () => { button.style.backgroundColor = '#1DB954'})
  50. button.addEventListener('mousedown', () => { button.style.backgroundColor = '#166e35'})
  51. button.addEventListener('mouseup', () => { button.style.backgroundColor = '#1DB954'})
  52.  
  53.  
  54.  
  55. button.addEventListener('click', function() {
  56. clickRandomNthItem('a#thumbnail.yt-simple-endpoint.inline-block.style-scope.ytd-thumbnail');
  57. button.style.top = '85%';
  58.  
  59. });
  60. document.body.appendChild(button);
  61. }
  62.  
  63. // Attendre que la page soit entièrement chargée avant de créer le bouton
  64. window.addEventListener('load', createButton);
  65.  
  66. })();