Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
80 lines (70 loc) · 2.62 KB
/
Copy pathbackground.js
File metadata and controls
80 lines (70 loc) · 2.62 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
//
//Basic Word Checking Program
//
// Basically, program gets all the information about a web page and checks if the word is on that webpage
// If it is, the extension will redirect you to google
// List with blocked words and phrases
let wordBlockList = [
// Insert most recent words that need to be blocked
// Format should be: ["word1", "word2"] etc.
];
let unblockedTime = [[8,40,8,50]];//8:40 -> 8:50 (Not inclusive at end point but inclusive at starting point)
function parseTime(){
let currentTime = new Date(new Date().getTime()).toLocaleTimeString().split(":");
let currentHour = parseInt(currentTime[0]);
let currentMinute = parseInt(currentTime[1]);
let currentSecond = parseInt(currentTime[2].slice(0,2));
if (currentTime[2][3] === "P"){
currentHour += 12;
}
// console.log("Current Hour: " + currentHour)
// console.log("Current Time: " + currentTime);
for (let unblockFrame of unblockedTime){
if ((parseInt(currentHour) >= unblockFrame[0])&&(parseInt(currentHour) <= unblockFrame[2])
&&(parseInt(currentMinute) >= unblockFrame[1])&&(parseInt(currentMinute) < unblockFrame[3])){
return true;//Within Time Period
}
}
return false;//Outside of Time Period
}
setInterval(parseTime, 2000);
chrome.tabs.onActivated.addListener(() => {
//console.log("onActivated Listener Running");
if (!parseTime()){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
//console.log(tabs);
chrome.tabs.sendMessage(tabs[0].id, {text: 'test'}, (response) => {
let websiteData = response.toString().toLowerCase();
for (let currentWord of wordBlockList){
if (websiteData.includes(currentWord)){
console.log(`Page Blocked Due To Word: ${currentWord}`);
let updating = chrome.tabs.update(tabs[0].id, {
active: true,
url: "https://www.google.com/"
});
}
}
});
});
}
});
chrome.tabs.onUpdated.addListener(() => {
//console.log("onUpdated Listener Running");
if (!parseTime()){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
//console.log(tabs);
chrome.tabs.sendMessage(tabs[0].id, {text: 'test'}, (response) => {
let websiteData = response.toString().toLowerCase();
for (let currentWord of wordBlockList){
if (websiteData.includes(currentWord)){
console.log(`Page Blocked Due To Word: ${currentWord}`);
let updating = chrome.tabs.update(tabs[0].id, {
active: true,
url: "https://www.google.com/"
});
}
}
});
});
}
});