Initial commit
This commit is contained in:
58
js/common.js
Normal file
58
js/common.js
Normal file
@ -0,0 +1,58 @@
|
||||
const UUP_API_ENDPOINT = 'https://api.uupdump.net/';
|
||||
|
||||
const STATUS_DIV_NAME = '#status';
|
||||
const STATUS_TITLE_NAME = '#status-title';
|
||||
const STATUS_TEXT_NAME = '#status-text';
|
||||
|
||||
const TEXT_ERROR = 'Error';
|
||||
const TEXT_PLEASE_WAIT = 'Please wait...';
|
||||
const TEXT_RETRIEVING_DATA = 'The data you requested is being retrieved...';
|
||||
|
||||
const $ = document.querySelector.bind(document)
|
||||
const $$ = document.querySelectorAll.bind(document)
|
||||
|
||||
async function getResponseFromApi(page, params) {
|
||||
let query = '';
|
||||
let data;
|
||||
|
||||
if(Object.keys(params).length != 0)
|
||||
query = '?' + new URLSearchParams(params).toString();
|
||||
|
||||
const url = `${UUP_API_ENDPOINT}${page}${query}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
data = await response.json();
|
||||
} catch(error) {
|
||||
return {'error': error.message};
|
||||
}
|
||||
|
||||
if(!('response' in data))
|
||||
return {'error': 'Response from the server is invalid.'};
|
||||
|
||||
return data['response'];
|
||||
}
|
||||
|
||||
function showSection(selector) {
|
||||
$(selector).classList.remove('hidden');
|
||||
}
|
||||
|
||||
function hideSection(selector) {
|
||||
$(selector).classList.add('hidden');
|
||||
}
|
||||
|
||||
function setStatusError(text) {
|
||||
$(STATUS_TITLE_NAME).innerHTML = TEXT_ERROR;
|
||||
$(STATUS_TEXT_NAME).innerHTML = text;
|
||||
showSection(STATUS_DIV_NAME);
|
||||
}
|
||||
|
||||
function setStatusLoading() {
|
||||
$(STATUS_TITLE_NAME).innerHTML = TEXT_PLEASE_WAIT;
|
||||
$(STATUS_TEXT_NAME).innerHTML = TEXT_RETRIEVING_DATA;
|
||||
showSection(STATUS_DIV_NAME);
|
||||
}
|
||||
|
||||
function clearStatus() {
|
||||
hideSection(STATUS_DIV_NAME);
|
||||
}
|
155
js/download.js
Normal file
155
js/download.js
Normal file
@ -0,0 +1,155 @@
|
||||
const UUP_PACKAGE_LINK = 'https://uupdump.net/get.php';
|
||||
|
||||
const BUILD_NAME = '#build-name';
|
||||
const BUILD_UUID = '#build-uuid';
|
||||
|
||||
const LANGUAGE_SELECTION = '#language-selection';
|
||||
const LANGUAGE_SELECTION_SELECT = '#language-selection-select';
|
||||
|
||||
const EDITION_SELECTION = '#edition-selection';
|
||||
const EDITION_SELECTION_LIST = '#edition-selection-list';
|
||||
|
||||
const DOWNLOAD_INFO = '#download-info';
|
||||
const DOWNLOAD_LINK = '#download-link';
|
||||
|
||||
const TEXT_NO_LANGUAGES = 'This build can\'t be downloaded.';
|
||||
const TEXT_UNSPECIFIED_BUILD = 'Build not specified.';
|
||||
const TEXT_SELECT_EDITION = 'Please select at least one edition.'
|
||||
|
||||
function addListenersToEditionOptions() {
|
||||
$$('.edition-option').forEach((x) => {
|
||||
x.addEventListener('click', () => {
|
||||
evaluateEditions();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateLanguageList(langList) {
|
||||
const langs = Object.values(langList);
|
||||
langs.sort();
|
||||
|
||||
const options = langs.map((x) => {
|
||||
return `
|
||||
<option value="${x}">
|
||||
${x}
|
||||
</option>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
$(LANGUAGE_SELECTION_SELECT).innerHTML = `
|
||||
<option value="">--- Please select ---</option>
|
||||
${options}
|
||||
`;
|
||||
|
||||
showSection(LANGUAGE_SELECTION);
|
||||
}
|
||||
|
||||
function updateEditionList(editionList) {
|
||||
const editions = Object.values(editionList);
|
||||
editions.sort();
|
||||
|
||||
const options = editions.map((x) => {
|
||||
return `
|
||||
<label>
|
||||
<input class="edition-option" type="checkbox" value="${x}">
|
||||
<code>${x}</code>
|
||||
</label>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
$(EDITION_SELECTION_LIST).innerHTML = options;
|
||||
addListenersToEditionOptions();
|
||||
showSection(EDITION_SELECTION);
|
||||
}
|
||||
|
||||
function updateBuildName(updateInfo) {
|
||||
const title = updateInfo['title'];
|
||||
const arch = updateInfo['arch'];
|
||||
|
||||
$(BUILD_NAME).innerHTML = `${title} ${arch}`;
|
||||
}
|
||||
|
||||
function buildDownloadLink(editions) {
|
||||
const editionsStr = editions.join(';').toLowerCase();
|
||||
const query = '?' + new URLSearchParams({
|
||||
'id': $(BUILD_UUID).value,
|
||||
'pack': $(LANGUAGE_SELECTION_SELECT).value,
|
||||
'edition': editionsStr,
|
||||
'autodl': 2
|
||||
}).toString();
|
||||
|
||||
return `${UUP_PACKAGE_LINK}${query}`;
|
||||
}
|
||||
|
||||
function evaluateEditions() {
|
||||
const selectedEditions = [];
|
||||
|
||||
for(const x of $$('.edition-option').values()) {
|
||||
if(x.checked)
|
||||
selectedEditions.push(x.value);
|
||||
}
|
||||
|
||||
if(selectedEditions.length < 1) {
|
||||
hideSection(DOWNLOAD_INFO)
|
||||
return;
|
||||
}
|
||||
|
||||
$(DOWNLOAD_LINK).href = buildDownloadLink(selectedEditions);
|
||||
showSection(DOWNLOAD_INFO);
|
||||
}
|
||||
|
||||
async function preparePage(uuid) {
|
||||
setStatusLoading();
|
||||
const response = await getResponseFromApi('listlangs.php', {'id': uuid});
|
||||
|
||||
if('error' in response) {
|
||||
setStatusError(response['error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if(response['langList'].length < 1) {
|
||||
setStatusError(TEXT_NO_LANGUAGES);
|
||||
return;
|
||||
}
|
||||
|
||||
updateBuildName(response['updateInfo']);
|
||||
updateLanguageList(response['langList']);
|
||||
clearStatus();
|
||||
}
|
||||
|
||||
async function languageSelected(uuid, lang) {
|
||||
hideSection(EDITION_SELECTION);
|
||||
hideSection(DOWNLOAD_INFO);
|
||||
|
||||
if(lang === "")
|
||||
return;
|
||||
|
||||
setStatusLoading();
|
||||
const response = await getResponseFromApi('listeditions.php', {'id': uuid, 'lang': lang});
|
||||
|
||||
if('error' in response) {
|
||||
setStatusError(response['error']);
|
||||
return;
|
||||
}
|
||||
|
||||
updateEditionList(response['editionList']);
|
||||
clearStatus();
|
||||
}
|
||||
|
||||
$(LANGUAGE_SELECTION_SELECT).addEventListener('change', async () => {
|
||||
const selection = $(LANGUAGE_SELECTION_SELECT).value;
|
||||
const uuid = $(BUILD_UUID).value;
|
||||
|
||||
await languageSelected(uuid, selection);
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
if(!window.location.hash) {
|
||||
setStatusError(TEXT_UNSPECIFIED_BUILD);
|
||||
return;
|
||||
}
|
||||
|
||||
const uuid = window.location.hash.substring(1);
|
||||
$(BUILD_UUID).value = uuid;
|
||||
preparePage(uuid);
|
||||
});
|
65
js/known.js
Normal file
65
js/known.js
Normal file
@ -0,0 +1,65 @@
|
||||
const SEARCH_FORM = '#search-builds';
|
||||
const SEARCH_INPUT = '#search-builds-query';
|
||||
const SEARCH_DATE_SORT = '#search-builds-date-sort';
|
||||
|
||||
const SEARCH_RESULTS = '#search-results';
|
||||
const SEARCH_RESULTS_TABLE = '#search-results-table-body';
|
||||
|
||||
function buildResultsTable(results) {
|
||||
const builds = Object.values(results['builds']);
|
||||
const table = builds.map((x) => {
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<a href="download.html#${x['uuid']}">
|
||||
${x['title']} ${x['arch']}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
${new Date(x['created'] * 1000).toLocaleDateString()}
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
$(SEARCH_RESULTS_TABLE).innerHTML = table;
|
||||
showSection(SEARCH_RESULTS);
|
||||
}
|
||||
|
||||
async function performSearch(search, sort) {
|
||||
const query = {
|
||||
'search': search,
|
||||
'sortByDate': sort
|
||||
}
|
||||
|
||||
hideSection(SEARCH_RESULTS);
|
||||
setStatusLoading();
|
||||
const response = await getResponseFromApi('listid.php', query);
|
||||
|
||||
if('error' in response) {
|
||||
setStatusError(response['error']);
|
||||
return;
|
||||
}
|
||||
|
||||
clearStatus();
|
||||
buildResultsTable(response);
|
||||
}
|
||||
|
||||
$(SEARCH_FORM).addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const search = $(SEARCH_INPUT).value;
|
||||
const sort = $(SEARCH_DATE_SORT).checked ? 1 : 0;
|
||||
window.location.hash = search;
|
||||
|
||||
await performSearch(search, sort);
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
if(!window.location.hash)
|
||||
return;
|
||||
|
||||
const search = window.location.hash.substring(1);
|
||||
$(SEARCH_INPUT).value = search;
|
||||
|
||||
await performSearch(search, 0);
|
||||
});
|
Reference in New Issue
Block a user