diff --git a/README.md b/README.md index 84d4c78..825735d 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ You should do this for **every** Chrome extension you use. Most extensions are c ### 🚮 Tab Cleaner Automatically closes inactive tabs after a configurable timeout (default: 5 minutes). Set excluded hosts to keep important tabs alive. View and re-open recently closed tabs. +### 🎯 Focus Blocker +Block distracting sites with one toggle. Add hosts (X, Reddit, Facebook, Instagram, YouTube, TikTok, etc.) and switch focus mode on — visiting them redirects to a "get back to what matters" page. Toggle individual sites on/off without deleting them. Suffix-matched, so `x.com` also blocks `mobile.x.com`. + ### 🍪 Cookie Editor Full cookie manager for the current site. View, edit, add, and delete cookies. Export cookies as JSON. Expand any cookie to see and modify all fields including domain, path, SameSite, secure, and httpOnly flags. diff --git a/background.js b/background.js index 3573677..c254559 100644 --- a/background.js +++ b/background.js @@ -223,3 +223,30 @@ chrome.runtime.onInstalled.addListener(() => { } }); }); + +// ═══════════════════════════════════ +// Focus Blocker +// ═══════════════════════════════════ +// Cancels top-level navigation to any host on the user's blocklist +// when focus mode is on, redirecting the tab to blocked.html. +chrome.webNavigation.onBeforeNavigate.addListener(async (details) => { + if (details.frameId !== 0) return; + if (!/^https?:/.test(details.url)) return; + + const data = await chrome.storage.local.get(["focus_enabled", "focus_sites"]); + if (!data.focus_enabled) return; + const sites = data.focus_sites || []; + if (!sites.length) return; + + let host; + try { host = new URL(details.url).hostname; } catch { return; } + + const hit = sites.find( + (s) => s.on && (host === s.host || host.endsWith("." + s.host)) + ); + if (!hit) return; + + chrome.tabs.update(details.tabId, { + url: chrome.runtime.getURL("blocked.html") + "?host=" + encodeURIComponent(host), + }); +}); diff --git a/blocked.html b/blocked.html new file mode 100644 index 0000000..e2775cd --- /dev/null +++ b/blocked.html @@ -0,0 +1,52 @@ + + +
+ + +… is blocked.
+Get back to what matters.
+