Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5dad591
add a write list to the backround
batiFinkelshtein Aug 1, 2024
79c0669
i add function to show the write list
batiFinkelshtein Aug 1, 2024
3cc626d
i update the scss file
batiFinkelshtein Aug 1, 2024
d0f37b5
update the content file
batiFinkelshtein Aug 1, 2024
a5d6917
i change some functions
batiFinkelshtein Aug 2, 2024
3adcf74
try to add logs
batiFinkelshtein Aug 4, 2024
de37331
I add button to function
batiFinkelshtein Aug 4, 2024
18a13d6
some updates in functions that they working
batiFinkelshtein Aug 4, 2024
f7eb5b5
i add checks to the button
batiFinkelshtein Aug 4, 2024
7794a96
I add function
batiFinkelshtein Aug 4, 2024
89d98a0
change the backround
batiFinkelshtein Aug 4, 2024
8a8c26b
change the content
batiFinkelshtein Aug 4, 2024
6cdf528
i remove all consols
batiFinkelshtein Aug 5, 2024
78340e9
i change the css to %
batiFinkelshtein Aug 5, 2024
dde1caa
i change the colors to variables
batiFinkelshtein Aug 5, 2024
cd6f3f4
i change the backround and popup to using with db
batiFinkelshtein Aug 5, 2024
055947d
i change that impossible to extend the list from the site
batiFinkelshtein Aug 5, 2024
3f94440
delete extend function
batiFinkelshtein Aug 5, 2024
3afde66
i change the popup
batiFinkelshtein Aug 5, 2024
c35e033
some changes in whiteList
batiFinkelshtein Aug 5, 2024
b84a331
add function to singin and send cookie
batiFinkelshtein Aug 6, 2024
8c7792f
Merge branch 'main' of https://github.com/SariGlick/TimeOut into bati…
batiFinkelshtein Aug 7, 2024
e970c4e
i add saved cookie
batiFinkelshtein Aug 7, 2024
90a4095
change the backround with api request
batiFinkelshtein Aug 7, 2024
ba315a2
update menifest
batiFinkelshtein Aug 7, 2024
c793899
the cookie is work!!!
batiFinkelshtein Aug 8, 2024
476bbd7
i fix some mistakes
batiFinkelshtein Aug 8, 2024
949d962
i change the site to http
batiFinkelshtein Aug 11, 2024
2c1a81b
the
batiFinkelshtein Aug 11, 2024
9b90eea
create base url
batiFinkelshtein Aug 12, 2024
b93d471
remove the console
batiFinkelshtein Aug 12, 2024
7523bd9
change the scss file
batiFinkelshtein Aug 12, 2024
e2aa9a2
move all the text to constant.js
batiFinkelshtein Aug 12, 2024
d7006c7
remove the Double code
batiFinkelshtein Aug 12, 2024
5ccaa00
i add service file
batiFinkelshtein Aug 12, 2024
4091389
add the service file
batiFinkelshtein Aug 12, 2024
50180e9
try to fix the fecth
batiFinkelshtein Aug 14, 2024
da78fd2
i create function to take the cookie from site
batiFinkelshtein Sep 1, 2024
4db865a
change the permission
batiFinkelshtein Sep 2, 2024
5bff874
i change the functions
batiFinkelshtein Sep 3, 2024
01ef2bb
i change the function
batiFinkelshtein Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8,223 changes: 4,303 additions & 3,920 deletions client-side/package-lock.json

Large diffs are not rendered by default.

121 changes: 87 additions & 34 deletions extension-ui/background.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,137 @@

let blockedSitesCache = null;
let allowedSitesCache = [];
let isBlackList = true;
let currentUserId = null;

chrome.runtime.onStartup.addListener(() => {
initializeCaches();
getUserIdFromTokenCookie();
});

chrome.runtime.onInstalled.addListener(() => {
initializeCaches();
getUserIdFromTokenCookie();
});

// Initialize cache when the extension is loaded
chrome.runtime.onStartup.addListener(() => initializeBlockedSitesCache());
chrome.runtime.onInstalled.addListener(() => initializeBlockedSitesCache());
function getUserIdFromTokenCookie() {
chrome.cookies.get({ url: "http://localhost:5000", name: "token" }, (cookie) => {
if (cookie) {
const token = cookie.value;
const userId = parseUserIdFromToken(token);
console.log("User ID:", userId);

function initializeBlockedSitesCache(callback) {
chrome.storage.local.get("blockedSites", (data) => {
} else {
console.log("Token cookie not found!");
}

});}

function parseUserIdFromToken(token) {
try {
const payload = JSON.parse(atob(token.split('.')[1]));
return payload.userId;
} catch (error) {
console.error("Failed to parse token:", error);
return null;
}
}


function initializeCaches(callback) {
chrome.storage.local.get(["blockedSites"], (data) => {
blockedSitesCache = data.blockedSites || [];
if (typeof callback === "function") {
callback();
}
});
}

// Use this function to ensure cache is initialized
function ensureBlockedSitesCacheInitialized(callback) {
function ensureCachesInitialized(callback) {
if (blockedSitesCache === null) {
initializeBlockedSitesCache(callback);
initializeCaches(callback);
} else if (typeof callback === "function") {
callback();
}
}

chrome.webNavigation.onBeforeNavigate.addListener((details) => {
ensureBlockedSitesCacheInitialized(() => {
ensureCachesInitialized(() => {
handleBeforeNavigate(details);
});
}, { url: [{ schemes: ['http', 'https'] }] });

function handleBeforeNavigate(details) {
try {
const url = new URL(details.url);

if (url.protocol === 'chrome:' || url.protocol === 'about:') {
return;
}

const hostname = url.hostname.toLowerCase();

if (blockedSitesCache.some(site => hostname.includes(site))) {
chrome.tabs.get(details.tabId, (tab) => {
if (tab.url.startsWith('chrome://') || tab.url.startsWith('about:')) {
return;
}
chrome.scripting.executeScript({
target: { tabId: details.tabId },
func: () => {
//TODO add UI for the oops window
window.stop();
window.location.href = chrome.runtime.getURL('oops.html');
}
}).catch(error => {
console.error("Error executing script: ", error);
});
});

if (isBlackList) {
if (blockedSitesCache.some(site => hostname.includes(site))) {
blockSite(details.tabId);
}
} else {
if (!allowedSitesCache.some(site => hostname.includes(site))) {
blockSite(details.tabId);
}
}
} catch (error) {
console.error("Invalid URL: ", error);
}
}

function blockSite(tabId) {
chrome.tabs.get(tabId, (tab) => {
if (tab.url.startsWith('chrome://') || tab.url.startsWith('about:')) {
return;
}
chrome.scripting.executeScript({
target: { tabId: tabId },
func: () => {
window.stop();
window.location.href = chrome.runtime.getURL('oops.html');
}
}).catch(error => {
console.error("Error executing script: ", error);
});
});
}

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'addBlockedSite') {
const hostname = request.hostname.toLowerCase();
ensureBlockedSitesCacheInitialized(() => {
ensureCachesInitialized(() => {
if (!blockedSitesCache.includes(hostname)) {
blockedSitesCache.push(hostname);
chrome.storage.local.set({ blockedSites: blockedSitesCache }, () => {
sendResponse({ success: true });
});
} else {
sendResponse({ success: false, message: 'Site already blocked' });
sendResponse({ success: false, message: "Site is already blocked." });
}
});
return true; // כדי להורות שהתגובה היא אסינכרונית
} else if (request.action === 'getBlockedSites') {
ensureBlockedSitesCacheInitialized(() => {
return true;
}

if (request.action === 'getMode') {
ensureCachesInitialized(() => {
sendResponse({ isBlackList: isBlackList });
});
return true;
}

if (request.action === 'getBlockedSites') {
ensureCachesInitialized(() => {
sendResponse({ blockedSites: blockedSitesCache });
});
return true; // כדי להורות שהתגובה היא אסינכרונית
return true;
}

if (request.action === 'getAllowedSites') {
sendResponse({ allowedSites: allowedSitesCache });
return true;
}
});
7 changes: 7 additions & 0 deletions extension-ui/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

const TEXTS = {
BLOCK_WEBSITES_BUTTON: 'Block Websites',
BROWSING_DATA_BUTTON: 'Browsing Data',
ENTER_SITE_BUTTON: 'Enter to Site',
CONTROL_PANEL_HEADING: 'Extension Control Panel',
};
25 changes: 16 additions & 9 deletions extension-ui/content.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
let blockedSitesCache = null;
let allowedSitesCache = null;
let isBlackList = true;

function initializeBlockedSitesCache(callback) {
chrome.storage.local.get("blockedSites", (data) => {
function initializeCache(callback) {
chrome.storage.local.get(["blockedSites", "allowedSites", "isBlackList"], (data) => {
blockedSitesCache = data.blockedSites || [];
allowedSitesCache = data.allowedSites || [];
isBlackList = data.isBlackList !== undefined ? data.isBlackList : true;
if (callback) callback();
});
}

initializeBlockedSitesCache(() => {
initializeCache(() => {
const hostname = window.location.hostname.toLowerCase();
const domain = hostname.split(".")[1];
if (blockedSitesCache && blockedSitesCache.includes(domain)) {
window.location.href = chrome.runtime.getURL('oops.html');

if (isBlackList) {
if (blockedSitesCache && blockedSitesCache.includes(hostname)) {
window.location.href = chrome.runtime.getURL('oops.html');
}
} else {
if (allowedSitesCache && !(allowedSitesCache.includes(hostname))) {
window.location.href = chrome.runtime.getURL('oops.html');
}
}
});


25 changes: 18 additions & 7 deletions extension-ui/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"manifest_version": 3,
"name": "Website Blocker7",
"version": "1.0",
"version": "3.0",
"description": "Blocks specified websites on Chrome using manifest v3",
"permissions": [
"cookies",
"storage",
"scripting",
"webNavigation",
"tabs",
"webNavigation",
"scripting",
"activeTab"


],
"host_permissions": [
"http://localhost:5000/*",
"http://*/*",
"https://*/*"
],
Expand All @@ -20,7 +24,14 @@
"action": {
"default_popup": "popup.html"
},
"web_accessible_resources":
[{"resources": ["oops.html"],
"matches": ["<all_urls>"]}]
}
"web_accessible_resources": [
{
"resources": ["oops.html"],
"matches": ["<all_urls>"]
}
],
"content_security_policy": {
"script-src": ["'self'", "https://*"],
"object-src": ["'self'"]
}
}
68 changes: 60 additions & 8 deletions extension-ui/popup.css
Original file line number Diff line number Diff line change
@@ -1,18 +1,70 @@
:root {
--background-color: #f8f9fa;
--container-background: #ffffff;
--button-background: #28a745;
--button-background-hover: #218838;
--text-color: #ffffff;
--border-color: #ced4da;
--list-background: #f1f3f5;
--list-border: #dee2e6; }

body {
font-family: Arial, sans-serif;
font-family: 'Roboto', Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #F0F0F0;
}
background-color: var(--background-color); }

.container {
text-align: center;
}
background-color: var(--container-background);
border-radius: 10px;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 80%;
max-width: 400px; }

.hidden {
display: none;
}
button {
background-color: var(--button-background);
color: var(--text-color);
border: none;
border-radius: 5px;
padding: 12px 20px;
margin: 10px 0;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s, transform 0.2s; }

button:hover {
background-color: var(--button-background-hover);
transform: translateY(-2px); }

form {
margin: 20px 0; }

input[type="text"] {
padding: 10px;
border: 1px solid var(--border-color);
border-radius: 5px;
width: 80%;
margin: 10px 0;
font-size: 14px; }

/*# sourceMappingURL=popup.css.map */
input[type="text"]:focus {
outline: none;
border-color: var(--button-background); }

ul {
list-style-type: none;
padding: 0; }

li {
background-color: var(--list-background);
border: 1px solid var(--list-border);
border-radius: 5px;
padding: 10px;
margin: 10px 0; }

.hidden {
display: none; }
1 change: 0 additions & 1 deletion extension-ui/popup.css.map

This file was deleted.

21 changes: 10 additions & 11 deletions extension-ui/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Website Blocker</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extension Popup</title>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<!-- TODO to use generic components and style this page -->
<div class="container">
<button id="blockSitesBtn">Block Websites</button>
<button id="browsingDataBtn">Browsing Data</button>
<button id="enterSite">Enter to Site</button>
<h2 id="controlPanelHeading"></h2>
<button id="blockSitesBtn"></button>
<button id="browsingDataBtn"></button>
<button id="enterSite"></button>
<div id="blockDiv" class="hidden">
<h3>Blocked Sites:</h3>
<h3>Blocked Sites</h3>
<ul id="blockedSitesList"></ul>
<form id="blockForm">
<input type="text" id="siteInput" placeholder="Enter site name">
<input type="text" id="siteInput" placeholder="Enter site URL">
<button type="submit">Block Site</button>
</form>
</div>
<div id="browsingDataDiv" class="hidden">
<h3>Browsing Data:</h3>
<p>This is where browsing data will be displayed.</p>
</div>
<div id="browsingDataDiv" class="hidden"></div>
</div>
<script src="constants.js"></script>
<script src="popup.js"></script>
</body>
</html>
Loading