summaryrefslogtreecommitdiff
path: root/extension/captureURL.js
diff options
context:
space:
mode:
Diffstat (limited to 'extension/captureURL.js')
-rw-r--r--extension/captureURL.js20
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()
+})()