-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopup.js
More file actions
68 lines (61 loc) · 2.04 KB
/
popup.js
File metadata and controls
68 lines (61 loc) · 2.04 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// settings loader thingy a
document.addEventListener('DOMContentLoaded', () => {
const options = ['fonts', 'colors', 'images', 'videos', 'cats', 'sounds'];
// Check if browser APIs are available
const browserAPI = window.chrome || window.browser;
if (!browserAPI) {
console.error('Browser API not found');
return;
}
// Use storage API with error handling
browserAPI.storage.local.get(
options.map(opt => `crazifier_${opt}`),
(result) => {
if (browserAPI.runtime.lastError) {
console.error('Storage error:', browserAPI.runtime.lastError);
return;
}
options.forEach(opt => {
const saved = result[`crazifier_${opt}`];
document.getElementById(opt).checked = saved === undefined ? true : saved;
});
}
);
options.forEach(opt => {
document.getElementById(opt).addEventListener('change', (e) => {
browserAPI.storage.local.set({
[`crazifier_${opt}`]: e.target.checked
}, () => {
if (browserAPI.runtime.lastError) {
console.error('Storage error:', browserAPI.runtime.lastError);
}
});
});
});
// let the chaos begin
document.getElementById('crazifyBtn').addEventListener('click', () => {
// save super cool settings
const settings = {};
options.forEach(opt => {
settings[`crazifier_${opt}`] = document.getElementById(opt).checked;
});
browserAPI.storage.local.set(settings, () => {
if (browserAPI.runtime.lastError) {
console.error('Storage error:', browserAPI.runtime.lastError);
return;
}
browserAPI.tabs.query({active: true, currentWindow: true}, ([tab]) => {
if (!tab || browserAPI.runtime.lastError) {
console.error('Tab query error:', browserAPI.runtime.lastError);
return;
}
browserAPI.scripting.executeScript({
target: { tabId: tab.id },
files: ['content.js']
}).catch(err => {
console.error('Script injection error:', err);
});
});
});
});
});