← All examples

JavaScript Privacy substack.com

Substack: block follow indicator emission

Intercepts fetch, XHR and sendBeacon calls so Substack cannot report that you viewed or followed the author.

Code to copy

// Suppress the "follow" indicator/beacon network calls
(function () {
  var BLOCK = [/\/api\/v1\/follow/i, /\/api\/v1\/notes\/.*\/seen/i, /\/api\/v1\/email\/seen/i];
  function blocked(url) { return BLOCK.some(function (rx) { return rx.test(url); }); }
  if (window.fetch) {
    var orig = window.fetch;
    window.fetch = function (input, init) {
      var u = typeof input === 'string' ? input : (input && input.url) || '';
      if (blocked(u)) { return Promise.resolve(new Response('', { status: 204 })); }
      return orig.call(this, input, init);
    };
  }
  var OrigXHR = window.XMLHttpRequest;
  if (OrigXHR) {
    var Patched = function () {
      var x = new OrigXHR();
      var open = x.open;
      x.open = function (m, u) {
        if (typeof u === 'string' && blocked(u)) { this.__jzBlocked = true; }
        return open.apply(this, arguments);
      };
      var send = x.send;
      x.send = function () {
        if (this.__jzBlocked) { return; }
        return send.apply(this, arguments);
      };
      return x;
    };
    Patched.prototype = OrigXHR.prototype;
    window.XMLHttpRequest = Patched;
  }
  if (navigator.sendBeacon) {
    var sb = navigator.sendBeacon.bind(navigator);
    navigator.sendBeacon = function (url, data) {
      if (blocked(String(url || ''))) { return true; }
      return sb(url, data);
    };
  }
})();

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. 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.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases