From 8adc7b0433fe67e6b34c04cbf52e34ac4d796754 Mon Sep 17 00:00:00 2001 From: Jinyuan Huang <88757735+BernieHuang2008@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:19:35 +0000 Subject: [PATCH 1/2] add a "copy" button to the "search-url" sidebar --- searx/static/themes/simple/src/js/main/results.js | 8 ++++++++ searx/static/themes/simple/src/less/style.less | 9 +++++++++ searx/templates/simple/elements/search_url.html | 1 + 3 files changed, 18 insertions(+) diff --git a/searx/static/themes/simple/src/js/main/results.js b/searx/static/themes/simple/src/js/main/results.js index 4eae58435..2309297df 100644 --- a/searx/static/themes/simple/src/js/main/results.js +++ b/searx/static/themes/simple/src/js/main/results.js @@ -16,6 +16,8 @@ } )); + d.querySelector('#search_url button#copy_url').style.display = "block"; + searxng.on('.btn-collapse', 'click', function () { var btnLabelCollapsed = this.getAttribute('data-btn-text-collapsed'); var btnLabelNotCollapsed = this.getAttribute('data-btn-text-not-collapsed'); @@ -41,6 +43,12 @@ } }); + searxng.on('#copy_url', 'click', function () { + var target = this.parentElement.querySelector('pre'); + navigator.clipboard.writeText(target.innerText); + this.innerText = this.dataset.copiedText; + }); + searxng.selectImage = function (resultElement) { /* eslint no-unused-vars: 0 */ if (resultElement) { diff --git a/searx/static/themes/simple/src/less/style.less b/searx/static/themes/simple/src/less/style.less index 8bb10bb06..87f747668 100644 --- a/searx/static/themes/simple/src/less/style.less +++ b/searx/static/themes/simple/src/less/style.less @@ -729,9 +729,18 @@ summary.title { #search_url { div.selectable_url { pre { + float: left; width: 200em; } } + + button#copy_url { + float: right; + padding: 0.4rem; + margin-left: 0.5rem; + border-radius: 0.3rem; + display: none; // will be shown by JS. + } } #links_on_top { diff --git a/searx/templates/simple/elements/search_url.html b/searx/templates/simple/elements/search_url.html index 9cc92b943..77c956dac 100644 --- a/searx/templates/simple/elements/search_url.html +++ b/searx/templates/simple/elements/search_url.html @@ -1,6 +1,7 @@