diff options
author | Simon Parri <simonparri@ganzeria.com> | 2025-09-23 10:13:09 -0500 |
---|---|---|
committer | Simon Parri <simonparri@ganzeria.com> | 2025-09-23 10:13:09 -0500 |
commit | 5d0fe787c423d834a6227f54cb69009993bdad69 (patch) | |
tree | 2b2e511cfe36505481479a58ab714a3b9194530c /extension/captureURL.js | |
parent | 0bbe831bcd186bd36b5f7b6b1c239a90c7dca5dd (diff) | |
download | TabFS-5d0fe787c423d834a6227f54cb69009993bdad69.tar.gz TabFS-5d0fe787c423d834a6227f54cb69009993bdad69.zip |
Rename currentURL.js to captureURL.js
Diffstat (limited to 'extension/captureURL.js')
-rw-r--r-- | extension/captureURL.js | 11 |
1 files changed, 11 insertions, 0 deletions
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() |