From 903066244ec7bb454d63eacc3f14b91523288f0e Mon Sep 17 00:00:00 2001 From: Simon Parri Date: Tue, 23 Sep 2025 10:30:06 -0500 Subject: Use IFFE in captureURL.js to avoid redeclaration errors --- extension/captureURL.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'extension/captureURL.js') diff --git a/extension/captureURL.js b/extension/captureURL.js index 0aeab92..0e71772 100644 --- a/extension/captureURL.js +++ b/extension/captureURL.js @@ -1,11 +1,13 @@ -function encode(str) { - return encodeURIComponent(str).replace("-", "%2D") -} +(() => { + 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 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() + let url = new URL(window.location) + if (anc) url.hash = anc + return url.toString() +})() -- cgit v1.2.3