-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
90 lines (79 loc) · 2.58 KB
/
popup.js
File metadata and controls
90 lines (79 loc) · 2.58 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
// Popup script
document.addEventListener("DOMContentLoaded", function () {
const checkButton = document.getElementById("checkOwnership");
const clearButton = document.getElementById("clearData");
const statusDiv = document.getElementById("status");
function showStatus(message, type = "info") {
statusDiv.textContent = message;
statusDiv.className = `status ${type}`;
statusDiv.style.display = "block";
if (type === "success") {
setTimeout(() => {
statusDiv.style.display = "none";
}, 3000);
}
}
function hideStatus() {
statusDiv.style.display = "none";
}
// Check ownership button click
checkButton.addEventListener("click", function () {
checkButton.disabled = true;
checkButton.textContent = "Checking...";
hideStatus();
// Get the active tab
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
// Check if we're on the right page
if (!tab.url.includes("autotrader.co.uk/car-search")) {
showStatus(
"Please navigate to an AutoTrader search page first",
"error",
);
checkButton.disabled = false;
checkButton.textContent = "Check Ownership";
return;
}
// Send message to content script
chrome.tabs.sendMessage(
tab.id,
{ action: "startOwnershipCheck" },
function (response) {
if (chrome.runtime.lastError) {
showStatus("Error: Please refresh the page and try again", "error");
console.error("Error:", chrome.runtime.lastError);
} else {
showStatus("Ownership check started...", "info");
}
checkButton.disabled = false;
checkButton.textContent = "Check Ownership";
},
);
});
});
// Clear data button click
clearButton.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
chrome.tabs.sendMessage(
tab.id,
{ action: "clearOwnershipData" },
function (response) {
showStatus("Ownership data cleared", "success");
},
);
});
});
// Listen for messages from content/background scripts
chrome.runtime.onMessage.addListener(function (
message,
sender,
sendResponse,
) {
if (message.action === "ownershipComplete") {
showStatus("Ownership check completed!", "success");
} else if (message.action === "ownershipError") {
showStatus("Error during ownership check", "error");
}
});
});