div.brdCmb, h1.pTtl { display: none; } #apksContainer img { max-height: 32px; } Add New Mod to the Database Add Versions Lists of all apks added in the database App Icon Upload App Name App Signature Publisher Requirements Category Size Description Add Mod Clear let appName = ''; let appSignature = ''; let inputPublisher = ''; let inputAppRequirements = ''; let inputAppCategory = ''; let inputSize = ''; let inputDescription = ''; let appIcon = ''; let isUpdating = false; const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; window.submit = async () => { }; window.addEventListener('load', async () => { await initFunctions(['ModalCreator', 'FirebaseModule', 'ImgurJS']); let auth = await supabase.auth.getUser(); if (!auth.data || auth.error) { window.alert("Invalid authorization!"); return; } auth = auth.data.user.id; if (auth != await FirebaseModule.fetchJSON('https://ptc-database-default-rtdb.firebaseio.com/admins/uid.json')) { window.alert("Invalid Authorization!"); return; } document.getElementById('clear').addEventListener('click', () => { document.getElementById('uploadForm').reset(); document.getElementById('submit').innerHTML = `<i class="upload icon"></i>Add Mod`; document.getElementById('profile_img').src = ''; isUpdating = false; }); (async () => { // retrieve all the icons in the firebase database of all the apks! const db = 'https://ptc-database-default-rtdb.firebaseio.com/mods'; let data = await FirebaseModule.fetchJSON(`${db}.json`); if (!data) { document.getElementById('profile_img').src = ''; document.getElementById('apksContainer').classList.remove('loader'); return; } let keys = Object.keys(data); keys.forEach((item) => { let img = document.createElement('img'); img.src = data[item].icon; img.style.cursor = 'pointer'; document.getElementById('apksContainer').appendChild(img); img.addEventListener('click', async () => { let temp_json = await FirebaseModule.fetchJSON(`${db}/${item}.json`); isUpdating = true; document.getElementById('inputAppName').value = temp_json.name; document.getElementById('inputAppSignature').value = atob(item); document.getElementById('inputPublisher').value = temp_json.publisher; document.getElementById('inputAppRequirements').value = temp_json.requirement; document.getElementById('inputAppCategory').value = temp_json.category; document.getElementById('inputSize').value = temp_json.size; document.getElementById('profile_img').src = temp_json.icon; document.getElementById('inputDescription').value = temp_json.description; appSignature = atob(item); document.getElementById('submit').innerHTML = `<i class="pencil alternate icon"></i>Update Mod`; }); }); document.getElementById('apksContainer').classList.remove('loader'); })(); document.querySelector('#uploadBtn').addEventListener('click', () => { document.querySelector('#file_attachments').click(); }, false); ImgurJS.uploadImgUr('file_attachments', 'profile_img', () => { query('uploadBtn').classList.add('loading'); query('uploadBtn').classList.add('disabled'); }, () => { query('uploadBtn').classList.remove('loading'); query('uploadBtn').classList.remove('disabled'); query('uploadBtn').innerHTML = "<i class=\"upload icon\"></i>Upload"; }, false); submit = async () => { let allInputs = document.querySelectorAll('#uploadForm input'); appName = allInputs[1].value; appSignature = allInputs[2].value; inputPublisher = allInputs[3].value; inputAppRequirements = allInputs[4].value; inputAppCategory = allInputs[5].value; inputSize = allInputs[6].value; inputDescription = document.querySelector('#inputDescription').value; document.getElementById('submit').classList.add('loading'); if (!document.getElementById('profile_img').src) { window.alert(`Please upload some icon for the game. Thank you!`); return; } appIcon = document.getElementById('profile_img').src; let apk_data = await FirebaseModule.fetchJSON(`${db}/${btoa(appSignature)}.json`); if (apk_data && !isUpdating) { ModalCreator.pop( `${new Date().getTime()}`, `<i class="exclamation circle large middle aligned icon"></i> Signature name is already Exists!`, `${appName} is already in the database.`, `exclamation circle large middle aligned icon`, `Reload`, `${window.location.href}`, `` ); document.getElementById('uploadForm').reset(); return; } let json_data = { downloads: 0, name: appName, icon: appIcon, publisher: inputPublisher, requirement: inputAppRequirements, category: inputAppCategory, size: inputSize, description: inputDescription } json_data = JSON.stringify(json_data); await FirebaseModule.patch(`${db}/${btoa(appSignature)}.json`, `${json_data}`); document.getElementById('uploadForm').reset(); document.getElementById('submit').classList.remove('loading'); ModalCreator.pop( `appModalID`, `<i class="check circle large middle aligned icon"></i> ${appName} is added/edited in the database successfully!`, `You have successfully added/updated the mod in the database.`, `check circle large middle aligned icon`, `Reload Page`, `${window.location.href}`, `` ); } }, false);