tidusx18
8/10/2017 - 3:34 PM

Use keyboard arrow left/right to go back/forward a month in Turnitin's date picker.

Use keyboard arrow left/right to go back/forward a month in Turnitin's date picker.

// ==UserScript==
// @name         Turnitin Date Picker Hotkeys
// @namespace    https://github.com/tidusx18
// @version      0.0.1
// @description  Adds action for "Arrow Left and Right" hotkey to go back and forward a month in Turnitin's date picker.
// @match        https://api.turnitin.com/t_modify_assignment.asp?*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	// NOTE: Refactor with specifically targeted elements this will work with.

	document.addEventListener("keydown", function(e) {
		submitPage(e);
	}, false);

	function submitPage(e) {
		if (e.keyCode === 37) {
			e.preventDefault();
			var backMonth = document.querySelector('.calnavleft'); // Back a month
			if (backMonth) {
				backMonth.click();
			}
		}

		if (e.keyCode === 39) {
			e.preventDefault();
			var forwardMonth = document.querySelector('.calnavright'); // Forward a month
			if (forwardMonth) {
				forwardMonth.click();
			}
		}
	}
	
	// document.addEventListener("keydown", function(e) {
    // console.log(e, e.key, e.keyCode);
	// }, false);

})();