Fixed Random Track buton on new website module
This commit is contained in:
parent
14404d0525
commit
cb85884d09
1 changed files with 13 additions and 4 deletions
|
@ -77,8 +77,7 @@ def randomize(listurl): # Data fetching and
|
||||||
class="play-button">
|
class="play-button">
|
||||||
← Main Page
|
← Main Page
|
||||||
</button>
|
</button>
|
||||||
<button onclick="window.open(document.links[Math.floor(Math.random() * document.links.length)].href)"
|
<button onclick="openRandomMusicCard()" class="play-button">
|
||||||
class="play-button">
|
|
||||||
Random Track →
|
Random Track →
|
||||||
</button>
|
</button>
|
||||||
</div>"""
|
</div>"""
|
||||||
|
@ -105,7 +104,7 @@ def randomize(listurl): # Data fetching and
|
||||||
|
|
||||||
# HTML block
|
# HTML block
|
||||||
html += f"""
|
html += f"""
|
||||||
<div class="music-card">
|
<div class="music-card" data-url="{yt_url}">
|
||||||
<div style="margin-bottom: 10px; display: flex; align-items: center;">
|
<div style="margin-bottom: 10px; display: flex; align-items: center;">
|
||||||
<span style="color: #888; margin-right: 10px;">#{musiccount}</span>
|
<span style="color: #888; margin-right: 10px;">#{musiccount}</span>
|
||||||
<span style="flex-grow: 1;">{title}</span>
|
<span style="flex-grow: 1;">{title}</span>
|
||||||
|
@ -117,7 +116,17 @@ def randomize(listurl): # Data fetching and
|
||||||
class="thumbnail"
|
class="thumbnail"
|
||||||
alt="{title} Cover Art"
|
alt="{title} Cover Art"
|
||||||
onerror="this.style.display='none'">
|
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:
|
except Exception as e:
|
||||||
print(f"Error processing: {music} - {str(e)}")
|
print(f"Error processing: {music} - {str(e)}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue