-
Notifications
You must be signed in to change notification settings - Fork 2
/
instances.js
170 lines (132 loc) · 4.62 KB
/
instances.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
console.log("'instances.js' loaded successfully")
function loadInstance(name, version, icon) {
const a = document.createElement('a');
const div = document.createElement('div');
div.className = 'instance';
// Attach version as a data attribute
a.setAttribute('instance-version', version);
a.onclick = function() {
selectInstance(name, version);
}
const img = document.createElement('img');
img.width = 50;
if (icon === 'default') {
img.src = 'assets/icons/grass.svg';
}
const p = document.createElement('p');
p.textContent = name;
div.appendChild(img);
div.appendChild(p);
a.appendChild(div);
const instances = document.querySelector('.instances');
instances.appendChild(a);
}
// Adds information on load
document.addEventListener('DOMContentLoaded', function() {
// lOADING VALUES
setTimeout(function(){
var rawinstancedata = localStorage.getItem('instancesdata')
var instancesdata = JSON.parse(rawinstancedata);
instancesdata.forEach(entry => {
loadInstance(entry.name, entry.version, entry.icon)
});
}, 5000);
});
// function addInstance(name) {
// const a = document.createElement('a');
// const div = document.createElement('div');
// div.className = 'instance';
// const img = document.createElement('img');
// img.width = 50;
// img.src = 'assets/icons/grass.svg';
// const p = document.createElement('p');
// p.textContent = name;
// div.appendChild(img);
// div.appendChild(p);
// a.appendChild(div);
// const instances = document.querySelector('.instances');
// instances.appendChild(a);
// };
function closeCreation() {
var bg = document.getElementById("dialogbg");
var dialog = document.getElementById("newinst");
dialog.classList.remove('popup');
dialog.classList.add('popout');
bg.classList.add('fadeout');
bg.classList.remove('fadein');
}
function startInstance() {
localStorage.setItem('launchname', window.__selectedName);
localStorage.setItem('launchversion', window.__selectedVersion);
window.parent.postMessage('launchminecraft', '*');
}
function selectInstance(name, version) {
var start = document.getElementById("startinst");
window.__selectedName = name
window.__selectedVersion = version;
// var edit = document.getElementById("editinst");
start.disabled = false;
// start.disabled = false;
}
function addInstance() {
const a = document.createElement('a');
const div = document.createElement('div');
div.className = 'instance';
// Attach version as a data attribute
a.setAttribute('instance-version', document.getElementById('mcversions').value);
a.onclick = function() {
selectInstance(document.getElementById('offlinename').value, document.getElementById('mcversions').value);
}
const img = document.createElement('img');
img.width = 50;
img.src = 'assets/icons/grass.svg';
const p = document.createElement('p');
p.textContent = document.getElementById('offlinename').value;
div.appendChild(img);
div.appendChild(p);
a.appendChild(div);
const instances = document.querySelector('.instances');
instances.appendChild(a);
localStorage.setItem('instance-name', document.getElementById('offlinename').value);
localStorage.setItem('instance-version', document.getElementById('mcversions').value);
localStorage.setItem('instance-icon', 'default');
window.parent.postMessage('newinstance', '*');
closeCreation();
};
// Adds information on load
document.addEventListener('DOMContentLoaded', function() {
window.parent.postMessage('awaitInstance', '*');
fetch('https://launchermeta.mojang.com/mc/game/version_manifest_v2.json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
const dropdown = document.getElementById('mcversions');
const versions = data.versions; // Access the versions array
versions.forEach(version => {
if (version.type === 'release') { // Check if type is 'release'
const option = document.createElement('option');
option.value = version.id;
option.textContent = version.id;
dropdown.appendChild(option);
}
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
});
function closeWindow() {
window.parent.postMessage('hideInstances', '*');
}
function newInstance() {
var bg = document.getElementById("dialogbg");
var dialog = document.getElementById("newinst");
bg.classList.add('fadein');
bg.classList.remove('fadeout');
dialog.classList.add('popup');
dialog.classList.remove('popout');
}