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 यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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();
	}
})();