Last active
June 1, 2023 19:04
-
-
Save sitek94/e39106c9a28204fc7616458f5d9bf14c to your computer and use it in GitHub Desktop.
Boost for Ahoy community to toggle focus mode
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
const styles = { | |
position: "fixed", | |
inset: 0, | |
zIndex: 99999, | |
overflowY: 'auto', | |
height: "100vh", | |
width: "100vw", | |
colorScheme: 'dark' | |
} | |
const toggleStyles = (() => { | |
let shouldApplyStyles = true; | |
return (element) => { | |
for (const [property, value] of Object.entries(styles)) { | |
element.style[property] = shouldApplyStyles ? value : 'unset'; | |
} | |
shouldApplyStyles = !shouldApplyStyles; | |
} | |
})(); | |
document.addEventListener('keydown', (event) => { | |
// 👇👇👇 CHANGE SHORTCUT HERE | |
if (event.ctrlKey && event.key === '=') { | |
const main = document.querySelector('div.main'); | |
toggleStyles(main); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment