Skip to content

Instantly share code, notes, and snippets.

@paulresdat
Last active April 8, 2024 22:39
Show Gist options
  • Save paulresdat/35c166ab15e0056ce1d046b9aa81748a to your computer and use it in GitHub Desktop.
Save paulresdat/35c166ab15e0056ce1d046b9aa81748a to your computer and use it in GitHub Desktop.
Repeat a track without having to push play over and over again
class BandcampPlay {
constructor() {
}
#interval = null;
repeatAll() {
var self = this;
if (this.#interval == null) {
this.#interval = setInterval(function() {
// check twice with a sleep indicator
var playing = true;
for (var i = 0; i < 2; i++) {
playing = self.checkPlayingAll();
}
if (!playing) {
// grab the first element
var $par = $('tr.track_row_view div.play_status').first();
$par.click();
}
}, 1000);
}
}
checkPlayingAll() {
var playing = false;
$('tr.track_row_view div.play_status').each(function() {
if ($(this).hasClass('playing')) {
playing = true;
}
});
return playing;
}
// single track use
repeat(buttonName) {
if (buttonName == null) {
buttonName = '.playbutton';
}
if (this.#interval == null) {
var $b = $(buttonName);
this.#interval = setInterval(function() {
if (!$b.hasClass('playing')) {
$b.click();
}
}, 1000);
}
}
stopRepeat() {
clearInterval(this.#interval);
this.#interval = null;
}
play(buttonName) {
if (buttonName == null) {
buttonName = '.playbutton';
}
var $b = $(buttonName);
if (!$b.hasClass('playing')) {
$b.click();
}
}
stop(buttonName) {
if (buttonName == null) {
buttonName = '.playbutton';
}
var $b = $(buttonName);
if ($b.hasClass('playing')) {
$b.click();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment