-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpopup.js
More file actions
91 lines (80 loc) · 3.49 KB
/
Copy pathpopup.js
File metadata and controls
91 lines (80 loc) · 3.49 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
document.addEventListener('DOMContentLoaded', function() {
const websiteInput = document.getElementById('websiteInput');
const addButton = document.getElementById('addButton');
const blockedList = document.getElementById('blockedList');
const saveButton = document.getElementById('saveButton');
const nameInput = document.getElementById('nameInput');
// const addNameButton = document.getElementById('addNameButton');
const group = document.getElementById('groupID');
const saveGroupButton = document.getElementById('saveGroupButton');
addButton.addEventListener('click', function() {
const website = websiteInput.value.trim();
if (website) {
const listItem = document.createElement('li');
listItem.textContent = website;
blockedList.appendChild(listItem);
websiteInput.value = '';
}
});
saveButton.addEventListener('click', function() {
const blockedWebsites = Array.from(blockedList.children).map(li => li.textContent);
const messageObj = {
action: "setWebsites",
websites: blockedWebsites,
groupId: group.value
};
console.log("Sending message:", messageObj);
chrome.runtime.sendMessage(messageObj);
});
saveUserButton.addEventListener('click',function(){
const messageObj = {
action: "setGroupId",
groupId: group.value,
username: nameInput.value
};
console.log("Sending message:", messageObj);
chrome.runtime.sendMessage(messageObj);
// chrome.runtime.sendMessage({groupId: group, username: nameInput}, function(response) {
// console.log(response.result);
// });
// chrome.storage.local.set({ username: nameInput });
// chrome.storage.local.set({ groupId: group }).then(() => {
// alert("value is set");
// console.log("Value is set");
// });
// alert("redirect");
// chrome.tabs.create({active: true, url: "https://www.youtube.com"});
});
// You may want to load and display any previously saved blocked websites when the popup opens.
// Example: chrome.storage.sync.get(['blockedWebsites'], function(result) {
// if (result.blockedWebsites) {
// result.blockedWebsites.forEach(website => {
// const listItem = document.createElement('li');
// listItem.textContent = website;
// blockedList.appendChild(listItem);
// });
// }
// });
// NOT WOWRKING RIGHT NOW!!!
// chrome.alarms.onAlarm.addListener(async (alarm) => {
// console.log("Alarm received");
// console.log(alarm);
// alarm = JSON.stringify(alarm);
// console.log(alarm);
// if (alarm.name === "prohibitedVisit") {
// // TODO: change username if the sever is working as intended
// alert(`User visited a prohibited website ${request.website}`);
// }
// });
});
// chrome.runtime.onMessage.addListener(
// (request, sender, sendResponse) => {
// if (request.action === "prohibitedVisit") {
// console.log("Receiving prohibited visit message")
// // TODO: change chrome.storage.local.get('username') if the sever is working as intended
// alert(`User ${chrome.storage.local.get('username')} visited a prohibited website ${request.website}`);
// }
// }
// );
function redirect(){
}