-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
51 lines (47 loc) · 1.36 KB
/
Copy pathbackground.js
File metadata and controls
51 lines (47 loc) · 1.36 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
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({
enabled: true,
threshold: 0.5,
categories: ['Porn', 'Hentai', 'Sexy'],
disabledDomains: []
});
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getSettings') {
chrome.storage.local.get(['enabled', 'threshold', 'categories', 'disabledDomains'], (result) => {
sendResponse(result);
});
return true;
}
if (request.action === 'updateSettings') {
chrome.storage.local.set(request.settings, () => {
sendResponse({ success: true });
});
return true;
}
if (request.action === 'fetchImage') {
fetch(request.url)
.then(response => response.blob())
.then(blob => {
if (!blob.type || !blob.type.startsWith('image/')) {
sendResponse({ error: 'Non-image content' });
return;
}
const reader = new FileReader();
reader.onloadend = () => {
sendResponse({ dataUri: reader.result });
};
reader.onerror = () => {
sendResponse({ error: 'Failed to read blob' });
};
reader.readAsDataURL(blob);
})
.catch(error => {
sendResponse({ error: error.message });
});
return true;
}
});
chrome.action.onClicked.addListener((tab) => {
chrome.action.openPopup();
});