Fixed Random Track buton on new website module

This commit is contained in:
Halhadus 2025-02-08 02:46:51 +03:00
parent 14404d0525
commit cb85884d09

View file

@ -77,8 +77,7 @@ def randomize(listurl): # Data fetching and
class="play-button">
Main Page
</button>
<button onclick="window.open(document.links[Math.floor(Math.random() * document.links.length)].href)"
class="play-button">
<button onclick="openRandomMusicCard()" class="play-button">
Random Track
</button>
</div>"""
@ -105,7 +104,7 @@ def randomize(listurl): # Data fetching and
# HTML block
html += f"""
<div class="music-card">
<div class="music-card" data-url="{yt_url}">
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="color: #888; margin-right: 10px;">#{musiccount}</span>
<span style="flex-grow: 1;">{title}</span>
@ -117,7 +116,17 @@ def randomize(listurl): # Data fetching and
class="thumbnail"
alt="{title} Cover Art"
onerror="this.style.display='none'">
</div>"""
</div>
<script>
function openRandomMusicCard() {{
const cards = document.querySelectorAll('.music-card[data-url]');
if (!cards.length) return alert('No music found!');
const randomCard = cards[Math.floor(Math.random() * cards.length)];
window.open(randomCard.dataset.url);
}}
</script>
"""
except Exception as e:
print(f"Error processing: {music} - {str(e)}")