-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Edit each entry's start and end time
- Loading branch information
1 parent
606db43
commit 5740ed6
Showing
8 changed files
with
363 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,3 @@ | ||
let blockedSites = []; | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
chrome.runtime.sendMessage({ action: 'getSites' }, function (response) { | ||
if (chrome.runtime.lastError) { | ||
console.error(chrome.runtime.lastError); | ||
return; | ||
} | ||
if (response && response.blockedSites) { | ||
blockedSites = response.blockedSites; | ||
updateBlockedSitesList(blockedSites); | ||
updateAutocompleteList(); | ||
} | ||
}); | ||
document.getElementById('openManager').addEventListener('click', function () { | ||
chrome.tabs.create({ url: 'settings.html' }); | ||
}); | ||
|
||
function updateAutocompleteList() { | ||
const sitesList = document.getElementById('sitesList'); | ||
const uniqueSites = [...new Set(blockedSites.map((site) => site.site))]; | ||
|
||
sitesList.innerHTML = ''; | ||
uniqueSites.forEach((site) => { | ||
const option = document.createElement('option'); | ||
option.value = site; | ||
sitesList.appendChild(option); | ||
}); | ||
} | ||
|
||
document.getElementById('addSite').addEventListener('click', function () { | ||
let siteInput = document.getElementById('siteInput'); | ||
let startTimeInput = document.getElementById('startTime'); | ||
let endTimeInput = document.getElementById('endTime'); | ||
|
||
let site = siteInput.value.trim(); | ||
let startTime = startTimeInput.value; | ||
let endTime = endTimeInput.value; | ||
|
||
if (site && startTime && endTime) { | ||
chrome.runtime.sendMessage( | ||
{ | ||
action: 'addSite', | ||
site: site, | ||
startTime: startTime, | ||
endTime: endTime, | ||
}, | ||
function (response) { | ||
if (chrome.runtime.lastError) { | ||
console.error(chrome.runtime.lastError); | ||
return; | ||
} | ||
if (response && response.blockedSites) { | ||
blockedSites = response.blockedSites; | ||
siteInput.value = ''; | ||
startTimeInput.value = '00:00'; | ||
endTimeInput.value = '23:59'; | ||
updateBlockedSitesList(blockedSites); | ||
updateAutocompleteList(); | ||
} else { | ||
console.error('Invalid response from background script'); | ||
} | ||
} | ||
); | ||
} | ||
}); | ||
|
||
function updateBlockedSitesList(sites) { | ||
let list = document.getElementById('blockedSitesList'); | ||
list.innerHTML = ''; | ||
sites.forEach(function (siteObj) { | ||
let li = document.createElement('li'); | ||
li.textContent = `${siteObj.site} (${siteObj.startTime} - ${siteObj.endTime})`; | ||
let removeButton = document.createElement('button'); | ||
removeButton.textContent = 'Remove'; | ||
removeButton.onclick = function () { | ||
chrome.runtime.sendMessage( | ||
{ | ||
action: 'removeSite', | ||
id: siteObj.id, | ||
}, | ||
function (response) { | ||
if (chrome.runtime.lastError) { | ||
console.error(chrome.runtime.lastError); | ||
return; | ||
} | ||
if (response && response.blockedSites) { | ||
blockedSites = response.blockedSites; | ||
updateBlockedSitesList(blockedSites); | ||
updateAutocompleteList(); | ||
} else { | ||
console.error('Invalid response from background script'); | ||
} | ||
} | ||
); | ||
}; | ||
li.appendChild(removeButton); | ||
list.appendChild(li); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Website Blocker Manager</title> | ||
<script src="tailwind.js"></script> | ||
</head> | ||
<body class="bg-gray-100 min-h-screen"> | ||
<div class="container mx-auto p-8"> | ||
<h1 class="text-3xl font-bold mb-8">Website Blocker Manager</h1> | ||
<div class="bg-white rounded-xl shadow-md p-6 mb-8"> | ||
<h2 class="text-2xl font-semibold mb-4">Add New Site</h2> | ||
<div class="mb-4"> | ||
<input | ||
type="text" | ||
id="siteInput" | ||
list="sitesList" | ||
placeholder="Enter website to block" | ||
class="w-full px-3 py-2 border rounded-md" | ||
/> | ||
<datalist id="sitesList"></datalist> | ||
</div> | ||
<div class="flex space-x-4 mb-4"> | ||
<input | ||
type="time" | ||
id="startTime" | ||
class="flex-1 px-3 py-2 border rounded-md" | ||
/> | ||
<input | ||
type="time" | ||
id="endTime" | ||
class="flex-1 px-3 py-2 border rounded-md" | ||
/> | ||
</div> | ||
<button | ||
id="addSite" | ||
class="w-full bg-blue-500 text-white px-4 py-2 rounded-md hover:bg-blue-600" | ||
> | ||
Add Site | ||
</button> | ||
</div> | ||
<div> | ||
<h2 class="text-2xl font-semibold mb-4">Blocked Sites</h2> | ||
<ul id="blockedSitesList" class="space-y-4"></ul> | ||
</div> | ||
</div> | ||
<script src="settings.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.