Last active
May 24, 2021 04:13
-
-
Save hannesfrank/23923dc5cfb9f38e46f2af3a04f957de to your computer and use it in GitHub Desktop.
A user script (for Violentmonkey etc.) which adds a few shortcuts to RemNote
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 RemNote Pane Management | |
// @namespace Violentmonkey Scripts | |
// @match https://www.remnote.io/document/* | |
// @grant none | |
// @version 0.1 | |
// @author Hannes Frank | |
// @description 25.11.2020, 15:37:16 | |
// ==/UserScript== | |
console.info('Running User Script: RemNote Focus Mode'); | |
const sidebarSelector = '#document-sidebar'; | |
const leftPaneSelector = '#multiple-windows__document:first-child'; | |
let leftPaneWidth = 50; | |
function remnoteEventListener(e) { | |
console.info(e); | |
let activeElement = document.activeElement; | |
if (e.code === 'Escape') { | |
activeElement.blur(); | |
} else if (e.code === 'KeyS' && !e.ctrlKey && !e.shiftKey && e.altKey && !e.metaKey) { | |
remnoteToggleSidebar(activeElement, e); | |
// TODO: Only do this in multipane layouts. | |
} else if (e.code === 'KeyH' && !e.ctrlKey && !e.shiftKey && e.altKey && !e.metaKey) { | |
console.info('shrinkLeft', leftPaneWidth); | |
shrinkLeft(); | |
e.preventDefault(); | |
} else if (e.code === 'KeyL' && !e.ctrlKey && !e.shiftKey && e.altKey && !e.metaKey) { | |
expandLeft(); | |
e.preventDefault(); | |
} | |
} | |
document.addEventListener('keydown', function (e) { | |
if (document.domain === 'www.remnote.io') { | |
remnoteEventListener(e); | |
} | |
}); | |
function remnoteIsSidebarActive() { | |
// .style only lists inline style, which does not work the first time | |
return getComputedStyle(document.querySelector(sidebarSelector)).display === 'flex'; | |
} | |
function remnoteToggleSidebar(activeElement, e) { | |
let sidebarDisplay = remnoteIsSidebarActive() ? 'none' : 'flex'; | |
document.querySelector(sidebarSelector).style.display = sidebarDisplay; | |
} | |
function shrinkLeft() { | |
leftPaneWidth = Math.max(leftPaneWidth - 5, 10); | |
updatePaneCSS(); | |
} | |
function expandLeft() { | |
leftPaneWidth = Math.min(leftPaneWidth + 5, 90); | |
updatePaneCSS(); | |
} | |
function updatePaneCSS() { | |
document.querySelector(leftPaneSelector).style.flex = `1 0 ${leftPaneWidth}%`; | |
} | |
// Ideas | |
// - (display: grid) and change width of the two pages | |
// - See roam spatial (ctrl + h/l) to move middle divider | |
// - maximize either page | |
// - use shortcut to set either page to small/wide | |
// - use :focuswithin to display the current page wider | |
// - use transform: scale to make a minimap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
Click the
Raw
button and your extension (Tampermonkey, Violentmonkey) should pick up the script.Usage
Default Shortcuts:
You can configure those in the lines 23 to 30 before importing the script.