Build

Turn rules into refusals

With a written boundary in hand, the code is mostly plumbing: a list of names, a function that decides whether a name is on it, something that intercepts requests, and a deliberately slow way to switch the whole thing off. Each piece is small enough to understand completely.

Starting point: a hosts file release, then a browser extensionExcerpts: plain text, JavaScript and JSON; all domains use reserved test names

Follow the steps in order

  1. Create the blocklist fileOne domain per line, lowercase, no scheme and no path. Comments start with a hash. This same file feeds every layer you build later, so keep it as the single source of truth.
  2. Ship a hosts file releaseGenerate hosts entries from the list, add them to the system hosts file with administrator rights, and flush the DNS cache. This is a complete first version and takes an evening.
  3. Write the matching functionA domain matches if it equals a listed name or ends with a dot followed by a listed name. This one rule handles subdomains, which the hosts file cannot.
  4. Build the extensionUse the browser's declarative request-blocking API to redirect gambling page loads to a pause page bundled with the extension. Generate the rules from the blocklist.
  5. Add the disable delayStore a timestamp when a disable is requested and only honour it after the waiting period from your boundary has passed. Clear the request if the person changes their mind.
  6. Design the pause pagePlain words, no shame, a reminder of the person's own reason for the blocker, and a link to a support page they chose in advance. Avoid a countdown or any element that feels like a game.
  7. Hand over the keyIf the boundary names a second person, set the administrator password or extension management so that person holds it, then test the arrangement on the checks page.

Blocklist format and matching

# blocklist.txt - one registrable domain per line
example-casino.test
sportsbook-mirror.test
odds-compare.example
A plain text list is easy to review in a diff, which matters when a second person checks changes.
function isBlocked(hostname, list) {
  const host = hostname.toLowerCase().replace(/\.$/, '');
  return list.some(d => host === d || host.endsWith('.' + d));
}

isBlocked('www.example-casino.test', list); // true
isBlocked('example-casino.test.', list);    // true (trailing dot stripped)
isBlocked('notexample-casino.test', list);  // false
Suffix matching with a leading dot prevents a listed name from matching a longer, unrelated one.

Normalise before matching: lowercase, strip a trailing dot, and convert internationalised names to their punycode form so that a lookalike written with non-Latin letters is compared on equal terms. Browsers and resolvers already present the punycode form in most APIs, but check rather than assume.

An extension rule that redirects to a pause

{
  "id": 1,
  "priority": 1,
  "action": {
    "type": "redirect",
    "redirect": { "extensionPath": "/pause.html" }
  },
  "condition": {
    "urlFilter": "||example-casino.test^",
    "resourceTypes": ["main_frame"]
  }
}
The || prefix matches the domain and all its subdomains; the ^ suffix stops the match at a separator.

Generate one rule per listed domain from the blocklist so the two never drift apart. Restricting the condition to top-level page loads keeps the rule focused on the moment of intent rather than on embedded images or scripts, which would create noisy failures on unrelated pages.

Permissions the code will ask for

Each permission is a promise about what the blocker can see. Ask for the smallest set and write down why each one is needed; that note belongs in the extension's description and in your own records.

declarativeNetRequest
Lets the browser apply blocking rules without the extension reading page contents. Preferred because the extension never sees the traffic itself.
storage
Holds the disable-request timestamp and the person's reason text. Nothing about browsing history needs to be stored.
host permissions
Only needed if the extension inspects pages for keywords. Limiting them to specific sites, rather than all URLs, is the safer default.
administrator rights
Required once to edit the hosts file or install a resolver. Whoever holds these can undo the blocker, which is why the boundary names a key holder.
VPN or filtering service permission (mobile)
Allows a local filtering interface where the platform permits it. Platform rules differ and change; read the current documentation for the device you are targeting.

A delay before the blocker can be switched off

const COOLDOWN_MS = 72 * 60 * 60 * 1000; // three days

function requestDisable(state, now) {
  if (!state.disableRequestedAt) {
    return { ...state, disableRequestedAt: now };
  }
  if (now - state.disableRequestedAt >= COOLDOWN_MS) {
    return { ...state, enabled: false, disableRequestedAt: null };
  }
  return state; // still waiting
}

function cancelDisable(state) {
  return { ...state, disableRequestedAt: null };
}
Pure functions that take the current time as an argument are easy to test without waiting three days.

Pass the clock in rather than reading it inside the function, so the test suite can simulate the passage of time. Store the timestamp somewhere the person cannot casually edit; for an extension that is its storage area, for a hosts-based blocker it may be a file owned by the key holder's account.