Random Video For Youtube

Play Random Video in Youtube

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

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