Skip to content

Instantly share code, notes, and snippets.

@munim
Last active September 29, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munim/242f99d2ab9cc7be5813912784ee0661 to your computer and use it in GitHub Desktop.
Save munim/242f99d2ab9cc7be5813912784ee0661 to your computer and use it in GitHub Desktop.
Tastaturnavigation für den WINDRIVE Theory-Trainer

Tastaturnavigation für den WINDRIVE Theory-Trainer

Mit Hilfe dieses Skripts und eines Chrome-Erweiterungs-Plugins können Sie die grundlegende Tastaturnavigation aktivieren, während Sie Probeprüfungen durchführen.

Tastatürkürzel:

Beschreibung Shortcut
Antwort 1 1
Antwort 2 2
Antwort 3 3
Erhöhen Sie die Videowiedergabegeschwindigkeit q
Video schließen w
Gehen Sie zur Aufgabe w
Wählen Sie Ja bei der Bestätigung der Frage w
Prüfe die Antwort w
Nächste Fragen w
Frage schließen c

Das Skript erfordert die Google-Erweiterung Script Runner Pro. Von hier herunterladen: https://chrome.google.com/webstore/detail/script-runner-pro/cofhgpcbaidjkjfbfglfhlklnbhajhpg?hl=de

Getestet und funktioniert wie erwartet am 29.09.2021

Script

// ==UserScript==
// @name WINDRIVE Theory Trainer Keyboard Navigation
// @namespace https://munim.net/userscript-windrive
// @version 0.1
// @match *://*.windrive-theorietrainer.de/*
// @author Munim
// @run-at document-idle
// ==/UserScript==

;(function () {

	let isKeyPressed = [];
	let enabled = false;

	const playbackConfig = {
		1.00: 1.25, 
		1.25: 1.50, 
		1.50: 1.75, 
		1.75: 2.00,
		2.00: 1.00
	};

	document.onkeydown = (keyDownEvent) => {   
		isKeyPressed[keyDownEvent.key] = true;  
		if (isKeyPressed['a'])
			enabled = !enabled;
		performAction();
	}
	
	const $xp = path => document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

	document.onkeyup = (keyUpEvent) => {
		focusAction();
		isKeyPressed[keyUpEvent.key] = false;
	};

	let focusAction = () => {
		if (!enabled) return;
		if (isKeyPressed['1']) {
			let inputField = $xp('//*[@id="questionnaireContent"]/tt-questionnaire-question//tt-questionnaire-input-question//input');

			if (inputField != null && document.activeElement !== inputField) {
				inputField.focus();
				inputField.value = '';
			}
		}
	}

	let performAction = () => {
		if (!enabled) return;

		let checkboxClick = id => {
			let ansCheckbox = $xp(`//*[@id="${id}"]`);
			
			if (ansCheckbox != null)
				ansCheckbox.click();
		};

		if (isKeyPressed['1'])
			checkboxClick('answerCheckbox1');
		else if (isKeyPressed['2'])
			checkboxClick('answerCheckbox2');
		else if (isKeyPressed['3'])
			checkboxClick('answerCheckbox3');
		else if (isKeyPressed['q']) {
			let video = $xp('//video[contains(@id, "vjs_video")]');
			
			video.playbackRate = (() => {
				let nextPlaybackRate = playbackConfig[video.playbackRate];
				return nextPlaybackRate ? nextPlaybackRate : 1;
			  })();
		}
		else if (isKeyPressed['w']) {
			let videoCloseButton = $xp('//*[@id="examVideoModal"][not(@hidden)]//kendo-dialog-actions/button[text()="Close"]');
			let toTaskButton = $xp('//*[@id="questionnaireContent"]//button[text()="To the task"]');
			let modalYesButton = $xp('//*[@id="loadQuestionModal"][not(@hidden)]//button[text()="Yes"]');
			let checkItButton = $xp('//*[@id="questionnaireButtons"]//button[text()="Check it"]');
			let nextButton = $xp('//*[@id="questionnaireButtons"]//button[text()="Next"]');


			if (videoCloseButton != null)
				videoCloseButton.click();
			else if (modalYesButton != null)
				modalYesButton.click();
			else if (toTaskButton != null)
				toTaskButton.click();
			else if (checkItButton != null)
				checkItButton.click();
			else if (nextButton != null)
				nextButton.click();
			else
				document.querySelector(".nextQuestion").click();
		}
		else if(isKeyPressed['c']) {
			let closeButton = $xp('//*[@id="questionnaireButtons"]//button[text()="Close"]');
			closeButton.click();
		}
		else if (isKeyPressed['e']) { 
			let playButton = document.querySelector(".playButton");
			if (playButton != null) {
				playButton.click();
				return;
			}
		  
			let video = $xp('//video[contains(@id, "vjs_video")]');
		  
			if (video != null)
				video.play();
		}
	}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment