forked from commit-man/liliths-mods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall.js
More file actions
126 lines (113 loc) · 4.28 KB
/
all.js
File metadata and controls
126 lines (113 loc) · 4.28 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
modList = document.getElementById("modList")
content = document.getElementById("content")
filter = document.getElementById("filter")
mods = []
//add non-git mod JSON url's to this array to test them
var modJSONS = []
hasRegex = function(dict, regex){
for (key in dict) {
if(Array.isArray(dict[key])){
for(string in dict[key]){
if(string.match(regex)) return true
}
}
else if(dict[key].match(regex)) return true
}
return false
}
filterEntries = function (){
var regex = filter.value
mods.forEach((mod, index) =>{
if(!regex || hasRegex(mod, regex)) modList.childNodes[index].style.display = ""
else modList.childNodes[index].style.display = "none"
})
}
modClicked = function(index){
// manage selected effect
var list = document.getElementsByClassName("active")
content.innerHTML = ""
for (var i = 0; i < list.length; i++) {
if (list[i] == modList.childNodes[index]){
// mod is deselected, show nothing
list[i].classList.remove("active")
return
}
list[i].classList.remove("active")
}
modList.childNodes[index].classList.add("active")
item = mods[index]
// define sub-structures
var images = ""
if(item.images && item.images.length > 0){
images += "<imgscroll>"
item.images.forEach(src => images += "<imgbox><img src='" + src + "'></imgbox>")
images += "</imgscroll>"
}
var info =
"<divider><p>Info</p><cloud>"
+ "<li>Author: " + item.author.replaceAll("<", "<")
+ "</li><li>last edited: " + item.last_edited.replaceAll("<", "<")
+ "</li><li>mod version: " + item.mod_version.replaceAll("<", "<")
+ "</li><li>Game version: " + item.LT_version.replaceAll("<", "<")
+ "</li></cloud></divider>"
var types = "<divider><p>Types</p><cloud>"
item.types.forEach(type => types += "<li>" + type + "</li>")
types += "</cloud></divider>"
var tags = ""
if(item.tags && item.tags.length > 0){
tags += "<divider><p>Tags</p><cloud>"
item.tags.forEach(tag => tags += "<li>" + tag + "</li>")
tags += "</cloud></divider>"
}
// define main structure
content.innerHTML
= "<h1>" + item.title + "</h1>"
+ "<a href = '" + item.url + "', target = '_blank', rel = 'noreferrer noopener'>Download</a>"
+ images
+ "<cloud>" + item.description + "</cloud>"
+ info
+ types
+ tags
}
generateModList = function(){
mods.forEach((item, index) => {
// get variables
var summary = ""
if(item.summary) summary = item.summary
else if (item.description) summary = item.description
var cover = ""
if(item.cover) cover = item.cover
else if(item.images[0]) cover = item.images.shift()
else cover = "https://raw.githubusercontent.com/Innoxia/liliths-throne-public/master/src/com/lilithsthrone/res/UIElements/menu.svg"
// assemble list item
modList.innerHTML +=
"<div onclick='modClicked(" + index + ")'>"
+ "<p>" + item.title + "</p>"
+ "<cloud>"
+ "<summary>" + summary + "</summary>"
+ "<imgbox><img src='" + cover + "'></imgbox>"
+ "</cloud>"
+ "</div>"
})
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
JSON.parse(xhttp.responseText).tree.forEach(item => modJSONS.push(item.path))
modJSONS.forEach(item => {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var mod = JSON.parse(xhttp.responseText)
mod.title = item.substr(0, item.length - 5).replaceAll("_", " ")
mods.push(mod)
if(mods.length == modJSONS.length) generateModList()
}
};
xhttp.open("GET", "mods/" + item, true);
xhttp.send();
})
}
};
xhttp.open("GET", "https://api.github.com/repos/commit-man/liliths-mods/git/trees/df69cac3bacf6965df1ee1be4809a360f38631f3", true);
xhttp.send();