nolageek / Discogs-Collection-Page

Generate a friendly view of your Discogs Media Collection
http://discogs.nolageek.com
5 stars 1 forks source link

Random Album Button #1

Closed laminateddenim closed 1 year ago

laminateddenim commented 1 year ago

Hi, great project, I'm using it to share my Discogs collection with houseguests, I have a QR code printed next to my record shelf that redirects to an AWS Elastic Beanstalk instance running this script.

I added a random album button, feel free to add it to your codebase if you like or change around as needed. I put it right at the end of the pagination/nav/filter bar.

<!-- Add a Random Button -->
<?php foreach ($collection['releases'] as $release)
$releaselinklist[] = "?releaseid=" . $release['id'];
?>

<script>
    var linklist = <?php echo json_encode($releaselinklist); ?>;
    function randomLink() {
        var i = parseInt(Math.random() * linklist.length);
        location.href = linklist[i];
    }
</script>

  <div class="btn-group btn-group-sm p-1" role="random" aria-label="Randomize">
    <a href="#" onclick="randomLink();" class="btn btn-info text-uppercase">RANDOM ALBUM</a>
  </div>
<!-- End of Random Button-->
nolageek commented 1 year ago

Nice, thanks! I'll check it out. Also, that's the exact reason I created this for myself - I do the same thing. :)

nolageek commented 1 year ago

I've been looking at this, but so far it's only able to pull the random from the current page (since $collection is pulled paginated.)

I'm trying to figure out a way to do this and randomize from the full collection, without downloading the entire collection's JSON just to pick a random release ID. I only have 300 items and that takes about 10 seconds to do (plus, technically the API limits you to 300 records I believe.)

nolageek commented 1 year ago

I was able to figure out a way to randomize based on the entirety of the collection (or whichever folder you're currently viewing) instead of just the current paginated set of items.

It works but I'm pretty certain I need to refactor some stuff this week and will do a code cleanup.