Last active
November 12, 2021 07:51
-
-
Save dclamage/4246112400e07c8aa22f1ff46c104cc8 to your computer and use it in GitHub Desktop.
Changes spacebar to toggle modes
This file contains 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 Fpuzzles-Spacebar | |
// @namespace http://tampermonkey.net/ | |
// @version 1.5 | |
// @description Changes spacebar and numpad enter to toggle modes | |
// @author Rangsk | |
// @match https://*.f-puzzles.com/* | |
// @match https://f-puzzles.com/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
const codes = ['Space', 'NumpadEnter']; | |
const doShim = function() { | |
'use strict'; | |
const prevOnKeyDown = document.onkeydown; | |
document.onkeydown = function(event) { | |
if (!codes.includes(event.code) || | |
disableInputs || | |
popup || | |
testPaused() || | |
toolCosmetics.includes(currentTool) || | |
event.ctrlKey || | |
event.altKey || | |
event.metaKey) { | |
prevOnKeyDown(event); | |
} else { | |
const modeCycle = ['Normal', 'Corner', 'Center', 'Highlight']; | |
const modeIndex = modeCycle.indexOf(enterMode); | |
setEnterMode(modeCycle[(modeIndex + 1) % modeCycle.length]); | |
} | |
} | |
} | |
let intervalId = setInterval(() => { | |
if (!document.onkeydown) { | |
return; | |
} | |
clearInterval(intervalId); | |
doShim(); | |
}, 16); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment