form.creator { border: 1px solid rgba(0,0,0,0.5); padding: 5px; } form input { border: 1px solid rgba(0,0,0,0.5); width: 100%; padding: 5px; } form label { font-weight: 550; line-height: 10px; } form textarea { font-weight: 550; line-height: 1rem; height: 300px; padding: 10px; width: 100%; border: 1px solid rgba(0,0,0,0.5); } div#preview_holder img { height: 300px; width: auto; aspect-ratio: 1/1; object-fit: cover; } button.disable-elem { opacity: 0.7; pointer-events: none; } Only Admins can post an announcement! Please write a good quality announcement that viewers would find it useful. Writing high quality, a good title, description, providing url, thumbnail and good information. Title Announcement (Paragraph) URL Attachments (Image) Post Announcement window.addEventListener('load', async() => { let user_data = ''; let img_src = ''; if (!await checkIfAdmin()) { document.querySelector('#announcement_form').innerHTML = ``; return; } window.submitForm = () => { submitForm(); } async function checkIfAdmin() { const ids = ["ef33a291-0a55-47e2-b56a-1fd64571b9fd"]; let LS_data = localStorage.getItem('user'); if (!LS_data) { window.alert(`No data in local storage.`); return; } user_data = atob(LS_data); try { user_data = JSON.parse(user_data); } catch (error) { window.alert(`${error}`); return; } let { data, error } = await supabase.auth.getSession(); if (error) { window.alert(`${error.message}`); return; } let user_id = data.session.user.id; if (!ids.includes(user_id)) { window.alert(`You are not admin`); return; } return true; } function submitForm() { document.getElementById('form_submit').classList.add('disable-elem'); let script = document.createElement('script'); script.src = 'https://rawcdn.githack.com/ptcreborn/battlecatsarchive/5421498d0d4408e19bc25ad9f61eebf54e5b97b6/DiscordAPI.js'; document.querySelector('head').appendChild(script); script.onload = async() => { //username, avatar, title, message, thumbnail, url await DiscordAPI.post( user_data.email, user_data.profile, document.querySelector('#form_title').value, document.querySelector('#form_message').value, img_src, document.querySelector('#form_url').value ); window.alert(`Your announcement has been posted!`); window.location.reload(); } } document.getElementById("file_attachments").addEventListener("change", async function() { const file = this.files[0]; let result = await uploadToImgBB(file); }); async function uploadToImgBB(file) { document.getElementById('form_submit').classList.add('disable-elem'); const apiKey = "07f1351d4e674784012d92ae6e03b49d"; // Replace with your API key const formData = new FormData(); formData.append("image", file); // file = File object (from input element) try { const response = await fetch( `https://api.imgbb.com/1/upload?key=${apiKey}`, { method: "POST", body: formData } ); const result = await response.json(); if (result.success) { document.getElementById('preview_holder').innerHTML = ''; let img = document.createElement('img'); img.src = result.data.thumb.url; img.style.minWidth = "130px"; img.style.flex = "1"; document.getElementById('preview_holder').appendChild(img); img_src = result.data.url; document.getElementById('form_submit').classList.toggle('disable-elem'); return result.data; } else { console.error("Upload failed:", result); document.getElementById('form_submit').classList.toggle('disable-elem'); } } catch (error) { console.error("Error:", error); document.getElementById('form_submit').classList.toggle('disable-elem'); } } }, false);