Skip to content

Instantly share code, notes, and snippets.

@Archonic944
Created August 19, 2024 19:27
Show Gist options
  • Save Archonic944/e03d94b6703669f7d47307f773b29c2b to your computer and use it in GitHub Desktop.
Save Archonic944/e03d94b6703669f7d47307f773b29c2b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name MusicNerd Auto-Play, Button Selector, and Next
// @namespace http://tampermonkey.net/
// @version 2.1
// @description Auto-click play button, number-key-based select song, auto press next musicnerd.io
// @author archonic
// @match https://musicnerd.io/quiz/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to simulate a space key press to play the track
function simulateSpaceKeyPress() {
const event = new KeyboardEvent('keydown', {
key: ' ',
code: 'Space',
keyCode: 32,
which: 32,
bubbles: true,
cancelable: true
});
document.dispatchEvent(event);
}
// Function to click the "Next" button
function clickNextButton() {
const buttons = document.querySelectorAll('button');
for (let button of buttons) {
if (button.innerHTML.trim().toLowerCase().includes('next') ||
button.classList.contains('bg-[rgba(239,209,101,1)]')) {
button.click();
break;
}
}
}
// Function to handle key presses for selecting song buttons
function handleKeyPress(event) {
const buttons = document.querySelectorAll('div.cursor-pointer');
if (event.key === '1' && buttons[0]) {
buttons[0].click(); // Click the first button
setTimeout(clickNextButton, 100); // Wait for 100ms before clicking the Next button
setTimeout(simulateSpaceKeyPress, 300); // Re-trigger play after 300ms
} else if (event.key === '2' && buttons[1]) {
buttons[1].click(); // Click the second button
setTimeout(clickNextButton, 100); // Wait for 100ms before clicking the Next button
setTimeout(simulateSpaceKeyPress, 300); // Re-trigger play after 300ms
} else if (event.key === '3' && buttons[2]) {
buttons[2].click(); // Click the third button
setTimeout(clickNextButton, 100); // Wait for 100ms before clicking the Next button
setTimeout(simulateSpaceKeyPress, 300); // Re-trigger play after 300ms
}
}
// Enable key selection
function enableKeySelection() {
document.addEventListener('keydown', handleKeyPress);
}
// Play the song when the page loads
window.addEventListener('load', () => {
simulateSpaceKeyPress();
});
// Enable key selection
enableKeySelection();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment