This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutils.js
69 lines (67 loc) · 1.91 KB
/
utils.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
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
function escapeHtml(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
function htmlToArray(collection) {
return [].slice.call(collection);
}
function htmlElement(str) {
var div = document.createElement('div');
div.innerHTML = str.trim();
return div.firstChild;
}
function httpGet(url) {
return new Promise((resolve,reject) => {
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", () => {
if (oReq.status==200) resolve(oReq.responseText)
else reject(oReq.status+" - "+oReq.statusText);
});
oReq.addEventListener("error", () => reject());
oReq.addEventListener("abort", () => reject());
oReq.open("GET", url);
oReq.send();
});
}
function toJS(txt) {
return JSON.stringify(txt);
}
// callback for sorting apps
function appSorter(a,b) {
if (a.unknown || b.unknown)
return (a.unknown)? 1 : -1;
var sa = 0|a.sortorder;
var sb = 0|b.sortorder;
if (sa<sb) return -1;
if (sa>sb) return 1;
return (a.name==b.name) ? 0 : ((a.name<b.name) ? -1 : 1);
}
/* Given 2 JSON structures (1st from apps.json, 2nd from an installed app)
work out what to display re: versions and if we can update */
function getVersionInfo(appListing, appInstalled) {
var versionText = "";
var canUpdate = false;
function clicky(v) {
return `<a href="#" onclick="showChangeLog('${appListing.id}')">${v}</a>`;
}
if (!appInstalled) {
if (appListing.version)
versionText = clicky("v"+appListing.version);
} else {
versionText = (appInstalled.version ? ("v"+appInstalled.version) : "Unknown version");
if (appListing.version != appInstalled.version) {
if (appListing.version) versionText += ", latest "+clicky("v"+appListing.version);
canUpdate = true;
}
}
return {
text : versionText,
canUpdate : canUpdate
}
}