commit 544a9c29079b259170c6c1da1fcb7262e0650b98
parent 4f695c1aa3003f3c16bfba6a6b33c300f5150e1b
Author: David Eisinger <[email protected]>
Date: Fri, 10 Oct 2025 10:49:28 -0400
Capture referrer in bookmarklet
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/internal/api.go b/internal/api.go
@@ -132,6 +132,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) {
// Popup form page
pageTitle := q.Get("t")
desc := q.Get("d")
+ refParam := q.Get("r")
pub := ""
if q.Get("p") != "" {
pub = q.Get("p")
@@ -184,6 +185,9 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) {
<label>Description
<textarea id="desc">%[3]s</textarea>
</label>
+ <label>Referrer
+ <input id="ref" type="text" value=%[8]s placeholder="https://site-that-linked-here.example">
+ </label>
<label><input id="pub" type="checkbox" %[4]s> Public</label>
<div class="actions">
<button type="submit">Save</button>
@@ -205,6 +209,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) {
url: document.getElementById('url').value.trim(),
title: document.getElementById('title').value.trim(),
description: (function(){const v=document.getElementById('desc').value; return v.trim() ? v : null;})(),
+ referrer: (function(){const v=document.getElementById('ref').value; return v.trim() ? v : (document.referrer||null);})(),
public: document.getElementById('pub').checked
};
try {
@@ -239,7 +244,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) {
return "checked"
}
return ""
- }(), origin, jsToken, jsUser)
+ }(), origin, jsToken, jsUser, enc(refParam))
})
// API token endpoint for logged-in user (regenerate only)
diff --git a/internal/web/app.js b/internal/web/app.js
@@ -229,7 +229,7 @@ createApp({
const auth = (this.api.value && this.me && this.me.username)
? `&user=${encodeURIComponent(this.me.username)}&tok=${encodeURIComponent(this.api.value)}`
: '';
- const tmpl = "javascript:(function(){try{var d=document,s=encodeURIComponent,u=location.href,t=document.title,sel='';var ae=d.activeElement;if(ae&&((ae.tagName==='TEXTAREA')||(ae.tagName==='INPUT'&&/^(?:text|search|url|tel|email)$/i.test(ae.type)))){var ss=ae.selectionStart||0,se=ae.selectionEnd||0;if(typeof ss==='number'&&typeof se==='number'&&se>ss){sel=ae.value.substring(ss,se)}}if(!sel&&d.getSelection){sel=d.getSelection().toString()}else if(!sel&&window.getSelection){sel=window.getSelection().toString()}else if(!sel&&d.selection){sel=d.selection.createRange().text}var win=window.open('{{ORIGIN}}/bookmarklet?u='+s(u)+'&t='+s(t)+'&d='+s(sel)+'{{AUTH}}','marky','width=520,height=520');if(win){win.focus()}}catch(e){alert('Could not open Marky: '+e)}})();";
+ const tmpl = "javascript:(function(){try{var d=document,s=encodeURIComponent,u=location.href,t=document.title,sel='';var ae=d.activeElement;if(ae&&((ae.tagName==='TEXTAREA')||(ae.tagName==='INPUT'&&/^(?:text|search|url|tel|email)$/i.test(ae.type)))){var ss=ae.selectionStart||0,se=ae.selectionEnd||0;if(typeof ss==='number'&&typeof se==='number'&&se>ss){sel=ae.value.substring(ss,se)}}if(!sel&&d.getSelection){sel=d.getSelection().toString()}else if(!sel&&window.getSelection){sel=window.getSelection().toString()}else if(!sel&&d.selection){sel=d.selection.createRange().text}var ref=d.referrer||'';var win=window.open('{{ORIGIN}}/bookmarklet?u='+s(u)+'&t='+s(t)+'&d='+s(sel)+'&r='+s(ref)+'{{AUTH}}','marky','width=520,height=520');if(win){win.focus()}}catch(e){alert('Could not open Marky: '+e)}})();";
return tmpl.replace('{{ORIGIN}}', origin).replace('{{AUTH}}', auth);
},
formatDate(iso) {