-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
55 lines (49 loc) · 1.56 KB
/
popup.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
// Copyright 2022 by [Chris Palmer](https://noncombatant.org)
// SPDX-License-Identifier: Apache-2.0
"use strict";
const log = function() {
errorsDiv.innerText = Array.from(arguments).join(" ")
console.log(...arguments)
}
const removeRuleIds = [...Array(chrome.declarativeNetRequest.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES).keys()].map(x => x + 1)
export const applyBlorpList = async function() {
const options = { addRules: [], removeRuleIds: removeRuleIds }
const patterns = localStorage.getItem("blorpList").split(/[\r\n]+/).map(p => p.trim()).filter(p => p.length > 0)
for (let i = 0; i < patterns.length; i++) {
const pattern = patterns[i]
options.addRules.push({
id: i + 1,
priority: 1,
action: { type: "block" },
condition: {
resourceTypes: [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"other"
],
urlFilter: pattern,
isUrlFilterCaseSensitive: false,
}
})
}
await chrome.declarativeNetRequest.updateDynamicRules(options)
log("Loaded", options.addRules.length, "rules")
}
const onApplyButtonClick = async function(event) {
localStorage.setItem("blorpList", blorpList.value)
await applyBlorpList()
}
document.body.onload = async function(event) {
blorpList.value = localStorage.getItem("blorpList")
applyButton.addEventListener("click", onApplyButtonClick)
}