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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RateYourMusic Collection Randomizer
// @version      2
// @license      CC0-1.0
// @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
// @author       https://github.com/Schwtz
// @match        https://rateyourmusic.com/collection/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rateyourmusic.com
// @grant        none
// @require      https://code.jquery.com/jquery-3.7.1.min.js
// @namespace    https://greasyfork.org/users/1439067
// ==/UserScript==

//random album
var albumButton = $('<a>');
albumButton.attr('class', 'btn');
albumButton.text('random album');
$('#content').prepend(albumButton);

albumButton.click(function() {
  var albumList = $('.album');
  var albumRandom = Math.floor(Math.random() * albumList.length);
  document.location = albumList[albumRandom].href;
});


//random collection page
var collectionButton = $('<a>');
collectionButton.attr('class', 'btn');
collectionButton.text('random page');
$('#content').prepend(collectionButton);

collectionButton.click(function() {
    var navList = $('.navlinknum');
    if(navList.length > 0) {
        var lastNum = navList[navList.length - 1];
        var randomPage = Math.floor(1 + Math.random() * lastNum.text);

        var firstNav = $('.navlinknum:first')
        var navLink = firstNav[0].href
        var ogURL = navLink.slice(0, -1)

        document.location = ogURL + randomPage;
    }
});