Hacker News: copy a clean link
Adds a button to each story that copies its address without tracking parameters, ready to share.
Code to copy
// Add a button to copy each story link with tracking params stripped
(function () {
document.querySelectorAll('.titleline > a:first-child').forEach(function (a) {
if (a.parentNode.querySelector('.jz-copy-clean')) { return; }
const btn = document.createElement('a');
btn.className = 'jz-copy-clean';
btn.textContent = ' [copy clean]';
btn.href = 'javascript:void(0)';
btn.style.cssText = 'color:#ff6600;font-size:8pt;margin-left:6px;cursor:pointer;';
btn.addEventListener('click', function () {
try {
const u = new URL(a.href);
['utm_source','utm_medium','utm_campaign','utm_term','utm_content',
'fbclid','gclid','ref','ref_src'].forEach(function (p) {
u.searchParams.delete(p);
});
navigator.clipboard.writeText(u.toString());
btn.textContent = ' [copied]';
setTimeout(function () { btn.textContent = ' [copy clean]'; }, 1500);
} catch (e) {}
});
a.parentNode.appendChild(btn);
});
})();
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.