Last active
November 12, 2021 07:50
-
-
Save dclamage/ca9aab30f3f5ae6438a40259bf8a2d41 to your computer and use it in GitHub Desktop.
Press ctrl+value with nothing selected to select all markings with that value
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-SelectValue | |
// @namespace http://tampermonkey.net/ | |
// @version 1.2 | |
// @description Press ctrl+value with nothing selected to select all markings with that value | |
// @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 doShim = function() { | |
'use strict'; | |
const prevOnKeyDown = document.onkeydown; | |
document.onkeydown = function(event) { | |
if ((event.key < '1' || event.key > '9') || | |
popup || | |
disableInputs || | |
testPaused() || | |
window.selection && window.selection.length !== 0 || | |
!event.ctrlKey || | |
event.altKey || | |
event.metaKey) { | |
prevOnKeyDown(event); | |
} else { | |
window.selection = []; | |
const val = event.key - '0'; | |
const size = window.size; | |
for (let i = 0; i < size; i++) { | |
for (let j = 0; j < size; j++) { | |
const cell = window.grid[i][j]; | |
if (cell.value === val || cell.centerPencilMarks.includes(val) || cell.cornerPencilMarks.includes(val)) { | |
selection.push(cell); | |
} | |
} | |
} | |
event.preventDefault(); | |
} | |
} | |
} | |
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