Last active
June 13, 2017 18:03
-
-
Save tidusx18/af51dbef6b0d413d00cd7e087436f58a to your computer and use it in GitHub Desktop.
Blackboard hotkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Submit/Save Hotkey (Ctrl + s) | |
// @namespace https://github.com/tidusx18 | |
// @version 0.0.1 | |
// @description Overrides browser default action for "Ctrl + s" hotkey to submit/save the current form/page. | |
// @author You | |
// @match https://fiu.blackboard.com/* | |
// @match https://cp.fiu.edu/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// NOTE: Refactor with specifically targeted elements this will work with. | |
document.addEventListener("keydown", function(e) { | |
submitPage(e); | |
}, false); | |
try { | |
getInstances(); // When hotkey pressed and focus is in TinyMCE editor | |
} catch(e) { | |
if(e instanceof ReferenceError) { | |
console.log('TinyMCE is not defined.'); | |
} | |
} | |
function submitPage(e) { | |
if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { | |
e.preventDefault(); | |
var submit = document.querySelector("input.submit"); // Common edit pages | |
if (submit) { | |
return submit.click(); | |
} | |
var update = document.querySelector("form input[value='Update']"); // TinyMCE HTML Popup | |
if (update) { | |
return update.click(); | |
} | |
var backLink = document.querySelector("p.backLink a"); // "Ok" buttons to return to previous page | |
if (backLink) { | |
return backLink.click(); | |
} | |
var closeButton = document.querySelector("[aria-labelledby=ui-id-6] .ui-dialog-buttonset button"); // CreatorPro | |
if (closeButton) { | |
return closeButton.click(); | |
} | |
} | |
} | |
function getInstances() { | |
return tinyMCE.onAddEditor.add( function(mgr,ed) { | |
ed.onKeyDown.add( function(ed, e) { | |
submitPage(e); | |
}); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment