-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
74 lines (67 loc) · 2.82 KB
/
background.js
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
// const keywordInput = document.getElementById('keyword-input');
function stringToList(inputString) {
const items = inputString.split(',').map(item => item.trim());
return items;
}
const data = {
keywordInput: [],
keywordWebsite: []
}
var isActive = 1;
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.keywordInput) {
data.keywordInput = stringToList(message.keywordInput);
} else if (message.keywordWebsite) {
data.keywordWebsite = message.keywordWebsite;
} else if (message.isActive == 0 || message.isActive == 1) {
isActive = message.isActive;
}
// console.log(data);
const url = 'http://192.3.249.51/verifyWebsite';
// const url = "http://10.20.7.21/verifyWebsite";
if(data.keywordInput.length>0 && data.keywordWebsite.length>0 && isActive) {
//send data to server
console.log(data);
var requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
};
fetch(url, requestOptions)
.then(response => {
if (response.ok) {
return response.json(); // or response.text() if the server sends plain text
} else {
throw new Error('Network response was not ok');
}
})
.then(data => {
// Handle the response data here
console.log(data);
//go to the active tab and delete the html of the page if data is 0
if(data == 0){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
function: () => {
document.documentElement.innerHTML = "";
document.documentElement.innerHTML = `<body style="text-align: center; background-color: #f5f5f5; font-family: Arial, sans-serif;">
<div style="margin: 100px auto; padding: 20px; background-color: #fff; border: 1px solid #ccc; border-radius: 5px; max-width: 600px;">
<h1 style="color: #d9534f;">Oops, You've Hit a Roadblock!</h1>
<p>This website doesn't align with your current mission. It's time to refocus and conquer your goals.</p>
<br>
<strong>Focii Extension</strong>
</div>
</body>`;
}
});
});
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
}
});