-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
47 lines (41 loc) · 1.68 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
chrome.history.onVisited.addListener(function(result) {
var searchData = {
text: '',
title: result.title,
data: result.url,
type: 1,
time_search: new Date().getTime()
};
chrome.storage.local.get({ searchHistory: [] }, function(result) {
var search = result.searchHistory;
var searchTmp = decodeURI(searchData.data);
// Kiểm tra từ nhạy cảm
fetch(chrome.runtime.getURL('json/sensitive_words.json'))
.then(response => response.json())
.then(data => {
var sensitiveWords = data.sensitiveWords;
for (var i = 0; i < sensitiveWords.length; i++) {
if (searchTmp.includes('https://www.google.com/search')) {
var searchQuery = new URL(searchTmp).searchParams.get('q');
if (searchQuery.toLowerCase().includes(sensitiveWords[i].toLowerCase())) {
searchData.text = sensitiveWords[i].toLowerCase();
search.push(searchData);
chrome.storage.local.set({ searchHistory: search });
// Chuyển hướng khi có từ nhạy cảm
chrome.tabs.update(result.id, { url: 'https://bocongan.gov.vn/lien-he.html' });
break;
}
} else {
if (searchTmp.toLowerCase().includes(sensitiveWords[i].toLowerCase())) {
searchData.text = sensitiveWords[i].toLowerCase();
search.push(searchData);
chrome.storage.local.set({ searchHistory: search });
// Chuyển hướng khi có từ nhạy cảm
chrome.tabs.update(result.id, { url: 'https://bocongan.gov.vn/lien-he.html' });
break;
}
}
}
});
});
});