I am trying to make a simple program to get the latest version from the GitHub API and compare it to a local JSON file. I have jQuery to make getting the information easier. If the version from the API is different from the local file, this script should print out that it is out of date in the console. But I keep on getting errors with the program not being able to read the variables, I tried making Cversion
and Lversion
to global variables putting it under window so you could call it with window.Cversion, but it still returned with undefined. I tried declaring the variables before like var Lversion;
, but same thing, undefined. Any tips?
This is the code for the main index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<p>Latest release: <span id="tag_name">Loading...</span></p>
<p>Current release (the site): <span id="version">Loading...</span></p>
<p>Is this site up to date? <span id="uptodate">Loading...</span></p>
<script src="jquery-3.2.1.min.js"></script>
<script>
$.getJSON("https://api.github.com/repos/3kh0/3kh0.github.io/releases/latest", function (data) {
window.Lversion = data.tag_name;
document.getElementById("tag_name").innerText = Lversion;
});
$.getJSON("about.json", function (cur) {
window.Cversion = cur.version;
document.getElementById("version").innerText = Cversion;
});
</script>
<script>
if (window.Lversion === window.Cversion) {
console.log("Up to date! " + window.Cversion);
document.getElementById("uptodate").innerText = "Yes";
} else {
console.warn("Out of date, latest version: " + window.Lversion);
document.getElementById("uptodate").innerText = "No";
}
</script>
</body>
</html>
about.json
{
"version": "v3-22.11.28"
}