This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheckforupdate.js
36 lines (30 loc) · 1.57 KB
/
checkforupdate.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
document.addEventListener("DOMContentLoaded", function() {
update();
});
function update()
{
// Get the current version
var currentVersion = document.getElementById("currentVersion").textContent.trim();
// Clear the warning and the latest version text
document.getElementById("update-warn").innerHTML = "";
// Get the latest version from the version.txt file
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Trim whitespace from the latest version
var latestVersion = this.responseText.trim();
document.getElementById("latestVersion").textContent = latestVersion;
console.log("Current version: " + currentVersion + "\nLatest version: " + latestVersion);
if (currentVersion !== latestVersion) {
document.getElementById("update-warn").innerHTML = "There is a new version available! <a href='https://github.com/LyubomirT/c.ai-addons/releases' target='_blank'>Download it here</a>.";
} else {
document.getElementById("update-warn").innerHTML = "You are using the latest version of the extension.";
}
}
};
xhttp.open("GET", "https://raw.githubusercontent.com/lyubomirt/c.ai-addons/main/version/version.txt", true);
xhttp.send();
document.getElementById("updateButton").addEventListener("click", function() {
update();
});
}