Skip to content

Instantly share code, notes, and snippets.

@steveRoll-git
Last active February 7, 2021 21:44
Show Gist options
  • Select an option

  • Save steveRoll-git/8b3192146b182c359610c3f9e83a17d2 to your computer and use it in GitHub Desktop.

Select an option

Save steveRoll-git/8b3192146b182c359610c3f9e83a17d2 to your computer and use it in GitHub Desktop.
Bandcamp Track Popularity Visualizer
{
function colorSongs(){
let elements = document.getElementsByClassName("fav-track")
let score = {}
let maxScore = 0
for(let i=0; i<elements.length; i++){
let e = elements[i];
let name = e.innerText.substring(16, e.innerText.length-1)
score[name] = score[name] == null ? 0 : score[name]
maxScore = Math.max(maxScore, score[name])
score[name]++
}
let targetColor = {
r: 211,
g: 173,
b: 48
}
let songElements = document.getElementsByClassName("track_row_view")
for(let i=0; i<songElements.length; i++){
let element = songElements[i];
let trackTitle = element.children[2].children[0].children[0]
//trackTitle.style.backgroundColor = "#00000075";
let songName = trackTitle.innerText
let value = score[songName] == undefined ? 0 : score[songName] / maxScore;
element.style.backgroundColor = `rgb(${value * targetColor.r}, ${value * targetColor.g}, ${value * targetColor.b})`
}
}
let targetSize = 100;
let prevCount = 0;
let timer;
function clickMore(){
let count = document.getElementsByClassName("writing").length
if(count >= targetSize || prevCount == count){
if(count >= targetSize){
console.log("got enough reviews. stopping");
}else if(prevCount == count){
console.log("no more reviews. stopping");
}
clearInterval(timer);
colorSongs()
return;
}
prevCount = count
console.log(`${count}/${targetSize} reviews - clicking again...`)
document.getElementsByClassName("more-writing")[0].click()
}
timer = setInterval(clickMore, 2500)
}
@steveRoll-git
Copy link
Author

On a Bandcamp album page, this script colors each track based on its popularity - how many people set a certain track as their "favorite track."

First, it clicks on the "more..." link until enough reviews are visible, or if there are no more reviews.

Usage

Paste this into your browser's console.

Note

The album needs enough reviews with "favorite track" in them in order to produce any meaningful results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment