Repository navigation
Expand file tree
/
Copy pathpopup.js
More file actions
114 lines (102 loc) · 4.63 KB
/
Copy pathpopup.js
File metadata and controls
114 lines (102 loc) · 4.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
document.addEventListener('DOMContentLoaded', async () => {
// Existing toggle settings for other filters...
const settings = [
{ checkboxId: 'toggleStickerFilterSwitch', key: 'stickerFilterEnabled' },
{ checkboxId: 'toggleFadeFilterSwitch', key: 'fadeFilterEnabled' },
{ checkboxId: 'toggleWatchFilterSwitch', key: 'watchFilterEnabled' },
{ checkboxId: 'toggleAppraisalFilterSwitch', key: 'appraisalFilterEnabled' },
{ checkboxId: 'toggleAppraisalDiscountedOnly', key: 'appraisalDiscountedOnly' }
];
// Existing slider definitions for other filters...
const sliders = [
{ sliderId: 'stickerThresholdSlider', key: 'stickerThreshold', displayId: 'stickerThresholdValue', inputId: 'stickerThresholdInput', default: 19 },
{ sliderId: 'fadeThresholdSlider', key: 'fadeThreshold', displayId: 'fadeThresholdValue', inputId: 'fadeThresholdInput', default: 90 },
{ sliderId: 'watchThresholdSlider', key: 'watchThreshold', displayId: 'watchThresholdValue', inputId: 'watchThresholdInput', default: 10 },
{ sliderId: 'appraisalThresholdSlider', key: 'appraisalThreshold', displayId: 'appraisalThresholdValue', inputId: 'appraisalThresholdInput', default: 0 }
];
// Load initial values from storage with new defaults for the paint seed filter.
const storedValues = await chrome.storage.local.get({
stickerFilterEnabled: false,
stickerThreshold: 19,
fadeFilterEnabled: false,
fadeThreshold: 90,
watchFilterEnabled: false,
watchThreshold: 10,
appraisalFilterEnabled: false,
appraisalThreshold: 0,
appraisalDiscountedOnly: false,
paintSeedFilterEnabled: false,
allowedPaintSeeds: "127"
});
// Initialize toggles for other filters...
settings.forEach(({ checkboxId, key }) => {
const toggle = document.getElementById(checkboxId);
toggle.checked = storedValues[key];
toggle.addEventListener('change', async () => {
await chrome.storage.local.set({ [key]: toggle.checked });
notifyContentScript();
});
});
// Initialize sliders for other filters...
sliders.forEach(({ sliderId, key, displayId, inputId, default: defaultValue }) => {
const slider = document.getElementById(sliderId);
const display = document.getElementById(displayId);
const inputBox = document.getElementById(inputId);
slider.value = storedValues[key] ?? defaultValue;
display.textContent = slider.value;
inputBox.value = slider.value;
slider.addEventListener('input', async () => {
display.textContent = slider.value;
inputBox.value = slider.value;
await chrome.storage.local.set({ [key]: parseFloat(slider.value) });
notifyContentScript();
});
inputBox.addEventListener('input', async () => {
slider.value = inputBox.value;
display.textContent = inputBox.value;
await chrome.storage.local.set({ [key]: parseFloat(inputBox.value) });
notifyContentScript();
});
});
// --- New: Initialize Paint Seed Filter elements ---
const paintSeedToggle = document.getElementById('togglePaintSeedFilterSwitch');
paintSeedToggle.checked = storedValues.paintSeedFilterEnabled;
paintSeedToggle.addEventListener('change', async () => {
await chrome.storage.local.set({ paintSeedFilterEnabled: paintSeedToggle.checked });
notifyContentScript();
});
const paintSeedInput = document.getElementById('paintSeedListInput');
paintSeedInput.value = storedValues.allowedPaintSeeds || "127";
paintSeedInput.addEventListener('input', async () => {
await chrome.storage.local.set({ allowedPaintSeeds: paintSeedInput.value });
notifyContentScript();
});
// Updated notify function to include paint seed filter settings
async function notifyContentScript() {
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tabs.length) return;
const updatedValues = await chrome.storage.local.get({
stickerFilterEnabled: false,
stickerThreshold: 19,
fadeFilterEnabled: false,
fadeThreshold: 90,
watchFilterEnabled: false,
watchThreshold: 10,
appraisalFilterEnabled: false,
appraisalThreshold: 0,
appraisalDiscountedOnly: false,
paintSeedFilterEnabled: false,
allowedPaintSeeds: "127"
});
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
files: ["contentScript.js"]
}, () => {
if (chrome.runtime.lastError) {
console.warn("Content script not injected:", chrome.runtime.lastError);
return;
}
chrome.tabs.sendMessage(tabs[0].id, updatedValues);
});
}
});