RateYourMusic Collection Randomizer

Add buttons to the top of all RYM collection pages which allows you to get a random album from a page or a random page of the current selected settings

  1. // ==UserScript==
  2. // @name RateYourMusic Collection Randomizer
  3. // @version 2
  4. // @license CC0-1.0
  5. // @description Add buttons to the top of all RYM collection pages which allows you to get a random album from a page or a random page of the current selected settings
  6. // @author https://github.com/Schwtz
  7. // @match https://rateyourmusic.com/collection/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=rateyourmusic.com
  9. // @grant none
  10. // @require https://code.jquery.com/jquery-3.7.1.min.js
  11. // @namespace https://greasyfork.org/users/1439067
  12. // ==/UserScript==
  13.  
  14. //random album
  15. var albumButton = $('<a>');
  16. albumButton.attr('class', 'btn');
  17. albumButton.text('random album');
  18. $('#content').prepend(albumButton);
  19.  
  20. albumButton.click(function() {
  21. var albumList = $('.album');
  22. var albumRandom = Math.floor(Math.random() * albumList.length);
  23. document.location = albumList[albumRandom].href;
  24. });
  25.  
  26.  
  27. //random collection page
  28. var collectionButton = $('<a>');
  29. collectionButton.attr('class', 'btn');
  30. collectionButton.text('random page');
  31. $('#content').prepend(collectionButton);
  32.  
  33. collectionButton.click(function() {
  34. var navList = $('.navlinknum');
  35. if(navList.length > 0) {
  36. var lastNum = navList[navList.length - 1];
  37. var randomPage = Math.floor(1 + Math.random() * lastNum.text);
  38.  
  39. var firstNav = $('.navlinknum:first')
  40. var navLink = firstNav[0].href
  41. var ogURL = navLink.slice(0, -1)
  42.  
  43. document.location = ogURL + randomPage;
  44. }
  45. });