← All posts

Action types

Copy-as-markdown and clean-URL toolbar buttons

JustZix JS rules run automatically on page load. Actions are different — they are toolbar buttons whose code runs only when you click them. That makes actions perfect for on-demand tools: copy the current page as markdown, clean tracking junk out of a URL, or rewrite links. Here are three you will use every day.

Action 1: copy the page title and URL as markdown

When you collect links for notes or documents, you want a tidy markdown link, not a raw URL. This action builds one and copies it to the clipboard.

var title = (document.title || location.hostname).trim();
var url = location.href;
var markdown = '[' + title + '](' + url + ')';

navigator.clipboard.writeText(markdown).then(function () {
  console.log('Copied: ' + markdown);
}).catch(function () {
  console.log('Clipboard blocked — copy manually: ' + markdown);
});

Because actions run on a click, the browser treats the clipboard write as a user gesture, so navigator.clipboard.writeText is allowed. A JS rule running on page load could not do this reliably.

Action 2: copy selected text as markdown

Select a heading and some text, click the button, and get markdown back. This version detects whether the selection sits inside a heading element.

var sel = window.getSelection();
var text = sel ? sel.toString().trim() : '';

if (!text) {
  console.log('Select some text first.');
} else {
  var node = sel.anchorNode;
  var el = node && node.nodeType === 3 ? node.parentElement : node;
  var tag = el ? (el.tagName || '').toLowerCase() : '';
  var prefix = '';
  if (tag === 'h1') prefix = '# ';
  else if (tag === 'h2') prefix = '## ';
  else if (tag === 'h3') prefix = '### ';

  navigator.clipboard.writeText(prefix + text);
  console.log('Copied as markdown.');
}

Action 3: strip tracking parameters from the URL

Shared links are often cluttered with utm_*, fbclid, gclid and similar tracking parameters. This action removes them and copies the clean URL — without reloading the page.

var JUNK = ['utm_source','utm_medium','utm_campaign','utm_term','utm_content',
            'fbclid','gclid','mc_eid','ref','ref_src','igshid','_hsenc'];

var u = new URL(location.href);
JUNK.forEach(function (param) {
  u.searchParams.delete(param);
});

var clean = u.toString();
navigator.clipboard.writeText(clean);
console.log('Clean URL copied: ' + clean);

If you also want the address bar to update, add history.replaceState(null, '', clean); — it rewrites the URL silently with no extra request.

Bonus: open all external links in new tabs

This one fits better as a JS rule (runs on load) than an action, but it pairs naturally with the tools above. It finds links pointing to other domains and marks them to open in a new tab safely.

var here = location.hostname;
var links = document.querySelectorAll('a[href^="http"]');

links.forEach(function (a) {
  try {
    if (new URL(a.href).hostname !== here) {
      a.target = '_blank';
      a.rel = 'noopener noreferrer';
    }
  } catch (e) { /* skip malformed href */ }
});

Setting rel="noopener noreferrer" is good practice — it stops the new page from getting a reference back to your tab.

When to use an action vs a rule

Browse pre-built buttons in the ready-made examples, or download JustZix to set them up. For automatic, load-time tweaks instead, see custom keyboard shortcuts.

Rate this post

No ratings yet — be the first.

Try it yourself

Install JustZix and paste any snippet from this article. Two minutes from zero to a working rule across all your devices.

Get JustZix

Features · How it works · Examples · Use cases