yerf.org audio controller

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
	}
})();