From 5d0fe787c423d834a6227f54cb69009993bdad69 Mon Sep 17 00:00:00 2001 From: Simon Parri Date: Tue, 23 Sep 2025 10:13:09 -0500 Subject: Rename currentURL.js to captureURL.js --- extension/background.js | 2 +- extension/captureURL.js | 11 +++++++++++ extension/currentURL.js | 11 ----------- 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 extension/captureURL.js delete mode 100644 extension/currentURL.js diff --git a/extension/background.js b/extension/background.js index 1b8960a..e5a46d0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -356,7 +356,7 @@ Routes["/tabs/by-id"] = { Routes["/tabs/by-id/#TAB_ID/capture-url.txt"] = { description: `Text file containing the current URL + text fragment of this tab.`, usage: 'cat $0', - ...routeFromScriptFile("/currentURL.js") + ...routeFromScriptFile("/captureURL.js") }; Routes["/tabs/by-id/#TAB_ID/active"] = { diff --git a/extension/captureURL.js b/extension/captureURL.js new file mode 100644 index 0000000..0aeab92 --- /dev/null +++ b/extension/captureURL.js @@ -0,0 +1,11 @@ +function encode(str) { + return encodeURIComponent(str).replace("-", "%2D") +} + +let sel = window.document.getSelection(), + ctx = sel?.anchorNode?.parentElement?.textContent?.split(sel), + anc = sel.toString() ? `:~:text=${ctx[0] ? encode(ctx[0])+"-," : ""}${sel}${ctx[1] ? ",-"+encode(ctx[1]) : ""}` : "" + +let url = new URL(window.location) +if (anc) url.hash = anc +url.toString() diff --git a/extension/currentURL.js b/extension/currentURL.js deleted file mode 100644 index 0aeab92..0000000 --- a/extension/currentURL.js +++ /dev/null @@ -1,11 +0,0 @@ -function encode(str) { - return encodeURIComponent(str).replace("-", "%2D") -} - -let sel = window.document.getSelection(), - ctx = sel?.anchorNode?.parentElement?.textContent?.split(sel), - anc = sel.toString() ? `:~:text=${ctx[0] ? encode(ctx[0])+"-," : ""}${sel}${ctx[1] ? ",-"+encode(ctx[1]) : ""}` : "" - -let url = new URL(window.location) -if (anc) url.hash = anc -url.toString() -- cgit v1.2.3