Spotify - Random Buttons

Add missing randomize features to Spotify.

Od 03.04.2023.. Pogledajte najnovija verzija.

  1. // ==UserScript==
  2. // @name Spotify - Random Buttons
  3. // @namespace spotify-random-buttons
  4. // @version 0.1
  5. // @description Add missing randomize features to Spotify.
  6. // @author Mark McEver
  7. // @match https://open.spotify.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. setTimeout(() => {
  13. const randomInteger = (min, max) => {
  14. return Math.floor(Math.random() * (max - min + 1)) + min
  15. }
  16.  
  17. const addRandomButton = (parent) => {
  18. const button = document.createElement('button')
  19. button.innerHTML = 'Random'
  20.  
  21. button.addEventListener('click', () => {
  22. const items = document.querySelectorAll('[data-testid=grid-container] a')
  23. const i = randomInteger(0, items.length)
  24. items[i].click()
  25. })
  26.  
  27. parent.appendChild(button)
  28. }
  29.  
  30. if(location.href.endsWith('/collection/artists')){
  31. const header = document.querySelector('main > section > div:first-child > h1')
  32. addRandomButton(header)
  33. }
  34. else if(location.href.endsWith('/discography/album')){
  35. const header = document.querySelector('main > section a').parentElement
  36. addRandomButton(header)
  37. }
  38. }, 3000)