123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // ==UserScript==
- // @name BetterYTM
- // @namespace https://github.com/Sv443/BetterYTM#readme
- // @version 0.1.0
- // @description:en Improvements for YouTube Music
- // @description:de Verbesserungen für YouTube Music
- // @author Sv443
- // @license MIT
- // @match https://music.youtube.com/watch*
- // @icon https://www.google.com/s2/favicons?domain=music.youtube.com
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- /**
- * This is where you can enable or disable features
- * If this userscript ever becomes something I might add like a menu to toggle these
- */
- const features = Object.freeze({
- /** Whether arrow keys should skip the video */
- arrowKeySupport: true,
- });
- //#MARKER init
- function init()
- {
- document.addEventListener("DOMContentLoaded", onDomLoad);
- }
- //#MARKER events
- /**
- * Called when the DOM has finished loading
- */
- function onDomLoad()
- {
- document.addEventListener("keydown", onKeyDown);
- }
- /**
- * Called when the user presses keys
- * @param {KeyboardEvent} evt
- */
- function onKeyDown(evt)
- {
- if(features.arrowKeySupport && ["ArrowLeft", "ArrowRight"].includes(evt.code))
- {
- switch(evt.code)
- {
- case "ArrowLeft":
- // ripped this stuff from the console, most of these are probably unnecessary but this was finnicky af and I am sick and tired of trial and error
- document.body.dispatchEvent(new KeyboardEvent("keydown", {
- altKey: false,
- bubbles: true,
- cancelBubble: false,
- cancelable: true,
- charCode: 0,
- code: "KeyH",
- composed: true,
- ctrlKey: false,
- currentTarget: null,
- defaultPrevented: evt.defaultPrevented,
- explicitOriginalTarget: document.body,
- isTrusted: true,
- key: "h",
- keyCode: 72,
- metaKey: false,
- originalTarget: document.body,
- repeat: false,
- shiftKey: false,
- srcElement: document.body,
- target: document.body,
- type: "keydown",
- view: window,
- which: 72,
- }));
- break;
- case "ArrowRight":
- // ripped this stuff from the console, most of these are probably unnecessary but this was finnicky af and I am sick and tired of trial and error
- document.body.dispatchEvent(new KeyboardEvent("keydown", {
- altKey: false,
- bubbles: true,
- cancelBubble: false,
- cancelable: true,
- charCode: 0,
- code: "KeyL",
- composed: true,
- ctrlKey: false,
- currentTarget: null,
- defaultPrevented: evt.defaultPrevented,
- explicitOriginalTarget: document.body,
- isTrusted: true,
- key: "l",
- keyCode: 76,
- metaKey: false,
- originalTarget: document.body,
- repeat: false,
- shiftKey: false,
- srcElement: document.body,
- target: document.body,
- type: "keydown",
- view: window,
- which: 76,
- }));
- break;
- default:
- console.warn("Unknown key", evt.code);
- break;
- }
- }
- }
- (() => init())();
|