[enh] add keybindings for copying URLs

'y': for in Vim-mode (yank)
'c': for SearXNG-mode (copy)

This should help keyboard heavy users
This commit is contained in:
Yaksh Bariya 2024-03-21 17:35:16 +05:30 committed by Markus Heiser
parent 8bf2da9ce5
commit 9f5268b4a7

View file

@ -63,6 +63,12 @@ searxng.ready(function () {
des: 'remove focus from the focused input', des: 'remove focus from the focused input',
cat: 'Control' cat: 'Control'
}, },
'c': {
key: 'c',
fun: copyURLToClipboard,
des: 'copy url of the selected result to the clipboard',
cat: 'Results'
},
'h': { 'h': {
key: 'h', key: 'h',
fun: toggleHelp, fun: toggleHelp,
@ -174,6 +180,12 @@ searxng.ready(function () {
des: 'select next search result', des: 'select next search result',
cat: 'Results' cat: 'Results'
}, },
'y': {
key: 'y',
fun: copyURLToClipboard,
des: 'copy url of the selected result to the clipboard',
cat: 'Results'
},
}, baseKeyBinding) }, baseKeyBinding)
} }
@ -435,6 +447,14 @@ searxng.ready(function () {
} }
} }
function copyURLToClipboard () {
var currentUrlElement = document.querySelector('.result[data-vim-selected] h3 a');
if (currentUrlElement === null) return;
const url = currentUrlElement.getAttribute('href');
navigator.clipboard.writeText(url);
}
searxng.scrollPageToSelected = scrollPageToSelected; searxng.scrollPageToSelected = scrollPageToSelected;
searxng.selectNext = highlightResult('down'); searxng.selectNext = highlightResult('down');
searxng.selectPrevious = highlightResult('up'); searxng.selectPrevious = highlightResult('up');