Skip to content

Instantly share code, notes, and snippets.

@Anamon
Created June 14, 2022 13:12
Show Gist options
  • Save Anamon/b46a6ba938fc0a8251c379af1b5e37fc to your computer and use it in GitHub Desktop.
Save Anamon/b46a6ba938fc0a8251c379af1b5e37fc to your computer and use it in GitHub Desktop.
Turntable Lab autoplay userscript
// ==UserScript==
// @name Turntable Lab autoplay
// @namespace https://www.turntablelab.com/
// @version 0.1
// @description Play all audio samples automatically.
// @author Daniel Saner
// @match https://www.turntablelab.com/products/*
// @icon https://www.google.com/s2/favicons?domain=turntablelab.com
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
var listenerAdded = false;
var currentTrack = 0;
var tracks = [];
waitForKeyElements ('.audio-track', addListener, true);
function addListener() {
if (!listenerAdded) {
listenerAdded = true;
const element = document.getElementsByClassName('product-gallery__tracks-button')[0];
element.children[0].textContent = 'PLAY ALL SAMPLES';
element.addEventListener('click', play);
}
}
function play() {
tracks = document.getElementsByClassName('audio-track__button');
tracks[currentTrack].click();
setTimeout(playNext, 1000);
}
function playNext() {
if (document.getElementsByClassName('audio-track--playing').length < 1) {
currentTrack++;
if (tracks.length > currentTrack) {
tracks[currentTrack].click();
} else {
currentTrack = 0;
return;
}
}
setTimeout(playNext, 1000);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment