-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
55 lines (47 loc) · 2.36 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
document.addEventListener('DOMContentLoaded', () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const url = tabs[0].url;
// Check if the current URL is a Discogs seller page
if (!url.includes('discogs.com/seller')) {
disableFilters();
}
});
const disableFilters = () => {
document.getElementById('condition').disabled = true;
document.getElementById('max-price').disabled = true;
document.getElementById('min-rating').disabled = true;
document.getElementById('min-want-have-ratio').disabled = true;
document.getElementById('apply-filters').disabled = true;
document.getElementById('apply-filters').style.backgroundColor = '#ccc'; // Update button style to show it's disabled
};
});
// Send the filtering criteria to the content script
document.getElementById('apply-filters').addEventListener('click', () => {
const condition = document.getElementById('condition').value;
const maxPrice = parseFloat(document.getElementById('max-price').value);
const minRating = parseFloat(document.getElementById('min-rating').value);
const minWantHaveRatio = parseFloat(document.getElementById('min-want-have-ratio').value);
console.log("Sending filters: ", { condition, maxPrice, minRating, minWantHaveRatio });
// Send the message to the content script with filter values
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
action: 'applyFilters',
conditionFilter: condition,
priceFilter: maxPrice,
ratingFilter: minRating,
wantHaveFilter: minWantHaveRatio
});
});
});
// Request the current filters when the popup opens
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: 'getFilters' }, (response) => {
if (response) {
// Update the popup fields with the current filter values from contentScript.js
document.getElementById('condition').value = response.conditionFilter || 'Very Good Plus (VG+)';
document.getElementById('max-price').value = response.priceFilter || 50;
document.getElementById('min-rating').value = response.ratingFilter || 4.5;
document.getElementById('min-want-have-ratio').value = response.wantHaveFilter || 1;
}
});
});