-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
46 lines (42 loc) · 1.14 KB
/
Copy pathcontentScript.js
File metadata and controls
46 lines (42 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function getDomain(url) {
try {
return new URL(url).hostname.replace("www.", "");
} catch {
return "";
}
}
function showBlockedScreen() {
document.documentElement.innerHTML = `
<body style="
background:#101820;
color:#f2f2f2;
font-family:system-ui,sans-serif;
display:flex;
align-items:center;
justify-content:center;
height:100vh;
text-align:center;">
<div>
<h1>Stay Focused 🔒</h1>
<p>This website is blocked during Focus Mode.</p>
<p><strong>−2 points</strong> penalty applied.</p>
<button onclick="history.back()">Go Back</button>
</div>
</body>
`;
}
chrome.storage.sync.get(
["isFocusOn", "focusEndTime", "blockedSites"],
(data) => {
if (!data.isFocusOn || Date.now() > data.focusEndTime) return;
const domain = getDomain(location.href);
const blocked = (data.blockedSites || []).some(site =>
domain.includes(site)
);
if (blocked) {
chrome.runtime.sendMessage({ action: "BLOCKED_SITE_VISITED" });
chrome.runtime.sendMessage({ action: "PAUSE_TIMER" });
showBlockedScreen();
}
}
);