wulkanowy.github.io/app.js

94 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-05-08 17:14:30 +02:00
var disableClick = function(e) {e.preventDefault()};
2018-06-14 19:08:39 +02:00
var addButtonInfo = function(url, prefix, cb) {
2018-06-20 00:26:57 +02:00
var buttonElement = document.querySelector("." + prefix + "-button");
if (null === buttonElement) {
return;
}
2018-05-08 17:14:30 +02:00
buttonElement.addEventListener("click", disableClick);
2018-06-20 00:26:57 +02:00
var versionElement = document.querySelector("." + prefix + "-version");
2018-05-08 17:14:30 +02:00
versionElement.innerHTML = "Ładowanie…";
2018-06-20 00:26:57 +02:00
var dateElement = document.querySelector("." + prefix + "-date");
2018-05-08 17:14:30 +02:00
var res = new XMLHttpRequest();
res.open("GET", url, true);
res.onloadend = function () {
if(res.status === 200) {
2018-06-14 19:08:39 +02:00
cb(res, buttonElement, versionElement, dateElement);
2018-05-08 17:14:30 +02:00
} else {
versionElement.innerHTML = "wersja nieznana";
}
buttonElement.removeEventListener("click", disableClick);
};
res.send(null);
};
2018-06-20 00:26:57 +02:00
if (null === document.querySelector(".button-container--list")) {
addButtonInfo("https://api.github.com/repos/wulkanowy/wulkanowy/releases/latest", "beta",
function(res, button, version, date) {
var json = JSON.parse(res.responseText);
button.href = json.assets[0].browser_download_url;
version.innerHTML = "v" + json.name;
date.innerHTML = new Date(json.published_at).toLocaleString("pl-PL");
}
);
2018-07-10 20:18:02 +02:00
addButtonInfo("https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/master/artifacts/0/info", "dev",
2018-06-20 00:26:57 +02:00
function(res, button, version, date) {
if (null !== document.querySelector(".button-container--list")) return;
var json = JSON.parse(res.responseText);
version.innerHTML = "Build " + json.build_number;
date.innerHTML = new Date(json.finished_at).toLocaleString("pl-PL");
}
);
}
(function (d) {
var list = d.querySelector(".button-container--list");
var base = d.querySelector(".button-container--list .button");
if (null === base) return;
var baseCopy = base.cloneNode(true);
base.style.display = "none";
var res = new XMLHttpRequest();
res.open("GET", "https://api.github.com/repos/wulkanowy/wulkanowy/branches", true);
res.onloadend = function () {
if(res.status === 200) {
JSON.parse(res.responseText).forEach(function (item) {
if ("master" === item.name) return;
2018-07-10 20:18:02 +02:00
var url = "https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/" + item.name + "/artifacts/0";
2018-06-20 00:26:57 +02:00
var branch = baseCopy.cloneNode(true);
branch.href = url;
branch.innerText = item.name;
var button_info = d.createElement("p");
button_info.setAttribute("class", "button__info");
var button_version = d.createElement("span");
button_version.setAttribute("class", "dev-version");
var button_date = d.createElement("span");
button_date.setAttribute("class", "dev-date");
button_info.appendChild(button_version);
button_info.appendChild(button_date);
addButtonInfo(url + "/info", "dev", function(res) {
var json = JSON.parse(res.responseText);
button_version.innerHTML = "Build " + json.build_number;
button_date.innerHTML = new Date(json.finished_at).toLocaleString("pl-PL");
});
branch.appendChild(button_info);
list.appendChild(branch);
})
}
};
res.send(null);
})(document);