-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdates.js
More file actions
68 lines (57 loc) · 1.98 KB
/
updates.js
File metadata and controls
68 lines (57 loc) · 1.98 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
const repos = [
{ owner: "Sangram03", repo: "Summaries_Chrome_Bot" },
];
const container = document.getElementById("updates-container");
Promise.all(
repos.map(r =>
fetch(`https://api.github.com/repos/${r.owner}/${r.repo}/releases/latest`)
.then(res => res.json())
.then(data => ({
name: `${r.owner}/${r.repo}`,
version: data.tag_name,
url: data.zipball_url
}))
)
).then(releases => {
container.innerHTML = "";
releases.forEach(r => {
const updateCard = document.createElement("div");
updateCard.className = "update-card";
updateCard.innerHTML = `
<b>${r.name}</b>: Latest version <b>${r.version}</b><br>
`;
const upgradeBtn = document.createElement("button");
upgradeBtn.textContent = "Upgrade";
upgradeBtn.className = "upgrade-btn";
upgradeBtn.addEventListener("click", () => {
const link = document.createElement("a");
link.href = r.url;
link.download = `${r.repo}-${r.version}.zip`;
link.click();
const restartBtn = document.createElement("button");
restartBtn.textContent = "Restart Extension";
restartBtn.className = "restart-btn";
restartBtn.addEventListener("click", () => chrome.runtime.reload());
updateCard.appendChild(restartBtn);
});
updateCard.appendChild(upgradeBtn);
container.appendChild(updateCard);
});
// Add Close (Back Home) Button
const closeBtn = document.createElement("button");
closeBtn.textContent = "⬅ Back to Home";
closeBtn.style.marginTop = "15px";
closeBtn.style.background = "#f44336";
closeBtn.style.color = "#fff";
closeBtn.style.border = "none";
closeBtn.style.borderRadius = "5px";
closeBtn.style.padding = "8px 12px";
closeBtn.style.cursor = "pointer";
closeBtn.addEventListener("click", () => {
window.close(); // closes this updates popup window
});
container.appendChild(closeBtn);
}).catch(err => {
container.innerHTML = "⚠️ Failed to fetch updates.";
console.error(err);
});