-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
92 lines (79 loc) · 2.75 KB
/
util.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
import { modal, modOutput, settings, VERSION } from './elements.js';
import { getDownloadList, getErrorMessages } from './modHandler.js';
// async function getModrinthDownloadLink(fileName) {
// const searchUrl = `https://api.modrinth.com/v2/search?query=${fileName}&limit=5`;
// try {
// const searchResponse = await fetch(searchUrl);
// const searchData = await searchResponse.json();
// for (let mod of searchData.hits) {
// const versionUrl = `https://api.modrinth.com/v2/project/${mod.slug}/version`;
// const versionResponse = await fetch(versionUrl);
// const versionData = await versionResponse.json();
// for (let version of versionData) {
// for (let i = 0; i < version.files.length; i++) {
// if (version.files[i].filename === fileName) {
// return version.files[i].url;
// }
// }
// }
// }
// return null;
// } catch (error) {
// return null;
// }
// }
// getModrinthDownloadLink('fileName').then(link => {
// console.log(link);
// });
export function extractFileName(url) {
const parts = url.split('/');
return parts[parts.length - 1];
}
async function fetechGitHubAPI(){
const response = await fetch('https://api.github.com/repos/thehousewashere/MinecraftModDownloader/releases')
if (!response.ok) {
return false;
}
return response.json();
}
export async function newVersion() {
const api = await fetechGitHubAPI();
if (!api){
return false;
}
return api[0]['name'] > VERSION;
}
export function setModal(title, body, footer, large) {
if (large){
modal.modalSize.className = 'modal-dialog modal-lg';
} else {
modal.modalSize.className = 'modal-dialog';
}
modal.modalTitle.innerHTML = title;
modal.modalBody.innerHTML = body;
modal.modalFooter.innerHTML = footer;
modal.modal.show();
}
export function modalClose() {
modal.modal.hide();
}
export function setOutput(title, body, color, border) {
modOutput.title.innerHTML = title;
modOutput.text.innerHTML = body;
modOutput.text.innerHTML = modOutput.text.innerHTML.replaceAll('>', '')
if (border) {
modOutput.div.setAttribute('class', `card border-${color}`);
} else {
modOutput.div.setAttribute('class', `card bg-${color}`);
}
}
export function getTimestamp() {
let date = new Date();
let formattedDate = date.getFullYear() + '-' +
('0' + (date.getMonth() + 1)).slice(-2) + '-' +
('0' + date.getDate()).slice(-2) + ' ' +
('0' + date.getHours()).slice(-2) + '-' +
('0' + date.getMinutes()).slice(-2) + '-' +
('0' + date.getSeconds()).slice(-2);
return formattedDate;
}