yerf.org audio controller

Unhides audio controls, adds hotkeys for said controls, adjusts some elements

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         yerf.org audio controller
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Unhides audio controls, adds hotkeys for said controls, adjusts some elements
// @author       GlawGlack
// @match        https://liltsome.yerf.org/*
// @grant        none
// @run-at       document-idle
// @license      unlicense
// ==/UserScript==

(function() {
	'use strict';

	function init() {

		const checkForAudio = setInterval(() => {
			const audioElement = document.querySelector('audio');

			if (audioElement && audioElement.src) {

				const movehere = document.querySelector('[class="player-progress"]');
				audioElement.controls = true;
				movehere.appendChild(audioElement);

				document.addEventListener('keydown', (e) => {
					if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
					switch(e.code) {
						case 'Space': e.preventDefault(); document.querySelector('[id="btnPlay"]').click(); break;

						case 'ArrowLeft': e.preventDefault(); if (event.key === 'ArrowLeft' && event.ctrlKey) {audioElement.currentTime = audioElement.currentTime - 10;}
							if (event.key === 'ArrowLeft') {audioElement.currentTime = audioElement.currentTime - 5;} break;
						case 'ArrowRight': e.preventDefault(); if (event.key === 'ArrowRight' && event.ctrlKey) {audioElement.currentTime = audioElement.currentTime + 10;}
							if (event.key === 'ArrowRight') {audioElement.currentTime = audioElement.currentTime + 5;} break;

						case 'ArrowUp': e.preventDefault(); audioElement.volume = audioElement.volume + 0.05; break;
						case 'ArrowDown': e.preventDefault(); audioElement.volume = audioElement.volume - 0.05; break;

						case 'KeyM': e.preventDefault(); if (audioElement.muted === true) {audioElement.muted = false;} else {audioElement.muted = true;} break;
					}
				});
				// smoosh default scrubber
				movehere.style.cssText =
					`
					width: 0px;
							  `;
				// make native larger
				audioElement.style.cssText =
					`
					display: unset !important;
					position: absolute !important;
					left: 20px !important;
					width: 75% !important;
					top: 50% !important;
									   `;
				// un-truncate current audio title
				document.querySelector('.player-title').style.cssText=
					`
					overflow: visible !important;
					white-space: wrap !important;
												`;
				clearInterval(checkForAudio);
			}
		}, 500);
	}

	if (document.readyState === 'loading') {
		document.addEventListener('DOMContentLoaded', init);
	} else {
		init();
	}
})();