Last active
January 11, 2017 16:51
-
-
Save evenfrost/621065c4c28b1422edf6 to your computer and use it in GitHub Desktop.
Adds Alt+Shift shortcut for swapping languages in Google Translate.
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
/** | |
* Adds Alt+Shift shortcut for swapping languages in Google Translate. | |
* Best used with browser JS injectors such as | |
* https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija | |
*/ | |
(function () { | |
var shiftKeyPressed = false, | |
altKeyPressed = false, | |
swap = document.querySelector('#gt-swap'); | |
window.addEventListener('keydown', function (event) { | |
var key = event.keyCode; | |
if (key === 16) | |
shiftKeyPressed = true; | |
else if (key === 18) | |
altKeyPressed = true; | |
if (shiftKeyPressed && altKeyPressed) { | |
swap.dispatchEvent(new MouseEvent('mouseover')); | |
swap.dispatchEvent(new MouseEvent('mousedown')); | |
swap.dispatchEvent(new MouseEvent('mouseup')); | |
shiftKeyPressed = false; | |
altKeyPressed = false; | |
} | |
}); | |
window.addEventListener('keyup', function (event) { | |
var key = event.keyCode; | |
if (key === 16) | |
shiftKeyPressed = false; | |
else if (key === 18) | |
altKeyPressed = false; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment