Skip to content

Instantly share code, notes, and snippets.

@EmilienD
Last active July 25, 2019 13:47
Show Gist options
  • Select an option

  • Save EmilienD/82abd2a70cb41d40537c47edf7e1c8b6 to your computer and use it in GitHub Desktop.

Select an option

Save EmilienD/82abd2a70cb41d40537c47edf7e1c8b6 to your computer and use it in GitHub Desktop.
User script to easily toggle document.designMode on a webpage
// ==UserScript==
// @name DesignMode toggler
// @version 1
// @grant none
// @include *
// ==/UserScript==
const shortcut = {
key: '1',
ctrlKey: true,
shiftKey: true,
}
const isShortcut = (sc, event) =>
Object.keys(sc).reduce(
(acc, propName) => sc[propName] === event[propName] && acc,
true,
)
document.addEventListener('keyup', e => {
if (isShortcut(shortcut, e)) {
document.designMode = document.designMode === 'off' ? 'on' : 'off'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment