diff options
author | Simon Parri <simonparri@ganzeria.com> | 2025-09-23 10:30:06 -0500 |
---|---|---|
committer | Simon Parri <simonparri@ganzeria.com> | 2025-09-23 10:30:45 -0500 |
commit | 903066244ec7bb454d63eacc3f14b91523288f0e (patch) | |
tree | 98b02b61fec8106bc17e3153098e02a99c243af0 /extension/captureURL.js | |
parent | 0daf56282286b959f6c6ebe8a3b634afa3aea3a8 (diff) | |
download | TabFS-903066244ec7bb454d63eacc3f14b91523288f0e.tar.gz TabFS-903066244ec7bb454d63eacc3f14b91523288f0e.zip |
Use IFFE in captureURL.js to avoid redeclaration errors
Diffstat (limited to 'extension/captureURL.js')
-rw-r--r-- | extension/captureURL.js | 20 |
1 files changed, 11 insertions, 9 deletions
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() +})() |