-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (27 loc) · 968 Bytes
/
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
// Fetch the filter list from the provided URL
fetch('https://raw.githubusercontent.com/piperun/iploggerfilter/master/filterlist')
.then(response => response.text())
.then(data => {
const filterList = data.split('\n').filter(line => line.trim() !== '' && !line.startsWith('!'));
chrome.runtime.onInstalled.addListener(() => {
const rules = filterList.map((url, index) => ({
id: index + 1,
priority: 1,
action: {
type: "redirect",
"redirect": {
"extensionPath": "/block.html"
}
},
condition: {
urlFilter: `||${url}^`,
resourceTypes: ["main_frame", "sub_frame"]
}
}));
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: Array.from({ length: filterList.length }, (_, index) => index + 1),
addRules: rules
});
});
})
.catch(error => console.error('Failed to fetch filter list:', error));