From c97d5c3dc5543a6beaa5e5562e48a09d93c3a2a6 Mon Sep 17 00:00:00 2001 From: Rithas K <74851056+rithask@users.noreply.github.com> Date: Sat, 14 May 2022 12:14:03 +0530 Subject: [PATCH] Feature: Shortcut key for new bookmark (#241) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add shortcut key for new bookmark * Use location.assign to keep history Co-authored-by: Sascha Ißbrücker --- bookmarks/static/shared.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bookmarks/static/shared.js b/bookmarks/static/shared.js index f4ab1f1..cc02f2d 100644 --- a/bookmarks/static/shared.js +++ b/bookmarks/static/shared.js @@ -61,6 +61,21 @@ event.preventDefault(); } }); + + // Add new bookmark + document.addEventListener('keydown', function(event) { + // Filter for new entry shortcut key + if (event.key !== 'n') return; + // Skip if event occurred within an input element + const targetNodeName = event.target.nodeName; + const isInputTarget = targetNodeName === 'INPUT' + || targetNodeName === 'SELECT' + || targetNodeName === 'TEXTAREA'; + + if (isInputTarget) return; + + window.location.assign("/bookmarks/new"); + }); } initConfirmationButtons();