yerf.org audio controller

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
	}
})();