<style> /* ---- CUSTOM ROOT PROPERTIES ---- */ .brdCmb, .pTtl { display: none; } :root { --bccats-border: 0 0 0 2px silver, 0 0 0 10px black, 0 0 0 10px silver; --bccats-bgColor: linear-gradient(rgb(65,60,44), rgb(24,23,19)); --bccats-bgColorInverted: linear-gradient(rgb(24,23,19), rgb(65,60,44)); --bccats-bgColor1: rgb(65,60,44); --bccats-bgColor2: rgb(24,23,19); --bccats-bgColor3: rgb(14,13,9); --cblock-bgColor1: #ebf; --cblock-bgColor1: #ffb; --cblock-textColor1: #222; --cblock-textColor1: #300; --cpost-bgColor1: #fdc; } /* ---- STYLING ---- */ .cpost-container, .cpost-container * { box-sizing: border-box; margin: 0; color: white; } .cpost-container { background: var(--bccats-bgColor); box-shadow: var(--bccats-border); padding: 0; } .cpost-item { padding: .5rem; border: 1px solid black; } .cpost-footer label:nth-child(2), .cpost-footer label > h3 { padding: .2rem; } .cpost-footer label:not(:last-child) > h3, .cpost-footer label:nth-child(2) > select { margin-bottom: .5rem; border: 1px solid orange; } .cpost-footer label:nth-child(2), .cpost-footer label > h3 { background: var(--bccats-bgColor); width: fit-content; } .cpost-footer label > h3:active, .cpost-footer label:nth-child(2):active { background: var(--bccats-bgColorInverted); transition: .25s; } .cpost-h3:before, .cpost-footer label:nth-child(2):before { content: "[ "; font-size: 1rem; font-weight: bold; } .cpost-h3:after, .cpost-footer label:nth-child(2):after { content: " ]"; font-size: 1rem; font-weight: bold; } .cpost-h1 { font-size: 2rem; margin: 0; } .cpost-h2 { font-size: 1.5rem; margin: 0; } .cpost-h3 { font-size: 1rem; margin: 0; } .cpost-p { font-size: 1rem; margin: 0; } .cpost-main textarea.cpost-p { width: 100%; padding: .2rem .7rem; outline: none; border: 2px inset var(--bccats-bgColor1); resize: none; background: var(--bccats-bgColor2); } .cpost-footer input, .cpost-footer button { display: none; } .cpost-footer select { background: none; border: none; outline: none; font-weight: bold; font-size: 1rem; } select option { background: black; } </style> <a class="button ln" href="https://storehaccounts.blogspot.com/p/battle-cats-gamer-community.html" style="margin-bottom: 20px;">Back to community</a> <br> <form class="cpost-container" action='javascript:postCheckpoint()'> <header class="cpost-item cpost-header"> <h2 class="cpost-h2">Create Post</h2> </header> <main class="cpost-item cpost-main"> <h3 class="cpost-h3">Title</h3> <textarea required id='pTitle' class="cpost-p" rows="1"></textarea> <h3 class="cpost-h3">Content</h3> <textarea required id='pDesc' class="cpost-p" rows="5"></textarea> </main> <footer class="cpost-item cpost-footer"> <label id='uploadImg'> <h3 class="cpost-h3">Upload Image</h3> <input style='display: none;' id='comm_imgupload1' accept="image/png, image/gif, image/jpeg, image/bmp" type="file" /> <div id='comm_form_attached_images'></div> </label> <label> <select required id='pCategory'> <option>Select Category</option> <option value='ACCOUNTS'>ACCOUNT CONCERNS</option> <option value='PACKS'>BCU PACKS</option> <option value='NEWS'>NEWS UPDATE</option> <option value='MODS'>BATTLE CATS MODS</option> <option value='SCRIPTS'>GAME GUARDIAN SCRIPTS</option> <option value='ASK-MOD'>MODDING QUESTIONS</option> <option value='FANARTS'>FANARTS</option> <option value='FANMADE'>FAN MADE</option> <option value='MEME'>MEME</option> <option value='OFF'>OFF-TOPIC</option> </select> </label> <label id='post_btn'> <h3 class="cpost-h3">Create Post</h3> <button type="submit"></button> </label> </footer> </form> <br> <script> //Functions //postCheckpoint() checks all inputs and determine needed information before posting. // To post, userrank of username must be retrieved. // Adding 10 points for the post.. // Then posting the post content. let rank_names = { "10": "Beginner", "30": "Trainee", "60": "Amateur", "120": "Hustler", "240": "Hotshot", "480": "Virtuoso", "960": "Expert", "1000": "Veteran", "1050": "Semi-Pro", "2000": "Professional", "2050": "Master", "2100": "Champ", "2200": "Superstar", "2500": "Hero", "3000": "Legend", "4000": "Immortal" }; let credentials = ''; let user_rank = ''; if (localStorage.getItem('ptc_credentials')) { credentials = localStorage.getItem('ptc_credentials'); } else window.location.href = "https://storehaccounts.blogspot.com/p/battle-cats-gamer-community.html"; function patch(url, data, callback) { let req = new XMLHttpRequest(); req.onload = () => { if (req.readyState == 4) if (req.status == 200) if (callback != null) callback(req.response); } req.onerror = (err) => { window.alert('Error encountered! ' + err); } req.open('PATCH', url, false); req.setRequestHeader('Content-Type', 'application/json'); req.setRequestHeader('Authorization', 'token 44489997-ed40-4f52-92a9-dfe6fe8ad5db'); req.send(JSON.stringify(data)); } function getUserRank(callback) { let req = new XMLHttpRequest(); req.onload = () => { if (req.readyState == 4) if (req.status == 200) callback(req.response); } req.onerror = (err) => { window.alert('Error encountered! ' + err); } req.open('GET', 'https://jsonbin.org/ptcreborn/ptc_user_ranks', false); req.setRequestHeader('Content-Type', 'application/json'); req.setRequestHeader('Authorization', 'token 44489997-ed40-4f52-92a9-dfe6fe8ad5db'); req.send(); } function successUserRank(data) { user_rank = data; } function determineRank(points) { let keys = Object.keys(rank_names); let rankName = ''; for (i = 0; i < keys.length; i++) { let rankPts = parseInt(keys[i]); if (points <= rankPts) { rankName = rank_names[keys[i]]; break; } } return rankName; } function successPost() { window.alert('Successfully Posted.'); } function postCheckpoint() { let title = checkTitle(); let description = checkDescription(); let images = checkImages(); let category = checkCategory(); let checkup = (title && description && images && category); if (checkup) { // Getting username and image credentials = JSON.parse(credentials); let username = credentials.username; let prof_img = credentials.img; delete credentials; // Getting user rank of this user getUserRank(successUserRank); user_rank = JSON.parse(user_rank); // user rank variables let rankName = ''; let rankPts = 0; let r_data; let feed_notif_data; let temp_id = new Date().getTime(); if (user_rank[username]) { let myKeys = Object.keys(user_rank[username].points); for(i=0; i<myKeys.length; i++) rankPts += parseInt(user_rank[username].points[myKeys[i]]); rankName = determineRank(rankPts); } else rankName = determineRank(2); r_data = { [username]: { "level": rankName, "points": { [new Date().getTime()]: "2", }, [category]: { [temp_id]: 1 } } } feed_notif_data = { [temp_id]: { "username": username, "title": title, "views": { } } } // update feed notifications patch('https://jsonbin.org/ptcreborn/ptc_feeds_notification', feed_notif_data, null); // update user rank patch('https://jsonbin.org/ptcreborn/ptc_user_ranks', r_data, null); // posting the post it self let post_data = { [temp_id]: { "user": { "username": username, "img": prof_img, "rank": rankName }, "posts": { "title": title, "description": description, "images": images }, "comments": {}, "category": category } } sendMessage( { "username": username, "avatar_url": prof_img, "content": (description.length > 200 ? description.substring(0, 200) + '...' : description), "embeds": [ { "title": title + ' (Battle Cats Community)', "description": (description.length > 200 ? description.substring(0, 200) + '...' : description), "url": "https://storehaccounts.blogspot.com/p/ptc-post-official.html?" + temp_id, "color": 15258703, "image": { "url": images[0] }, "footer": { "text": "Join our community now! :smirk:", } } ] }, "https://discord.com/api/webhooks/1173604024818343949/zeF51Tqg1-6rZQMmnfPHzRsrLPNN3g4P2U50k3tru4yPvx0eh3gHeLIpN1aGyrLimTSp", ).catch((error) => console.error(error)); let comment_data = { [temp_id]: {} } patch('https://jsonbin.org/ptcreborn/ptc_feeds', post_data, null); patch('https://jsonbin.org/ptcreborn/ptc_comments', comment_data, null); window.location.href = 'https://storehaccounts.blogspot.com/p/ptc-post-official.html?' + temp_id; } else window.alert('Some fields are not yet completed! Upload at least 1 image and select category.'); } function q(id) { return document.getElementById(id); } function checkTitle() { // if empty it will return false if (q('pTitle').value.length > 0) return q('pTitle').value; else return false; } function checkDescription() { // if empty it will return false if (q('pDesc').value.length > 0) return q('pDesc').value; else return false; } function checkImages() { // if empty it will return false; if (q('comm_form_attached_images').hasChildNodes()) { let imgs = []; let corrupted = false; for (i = 0; i < document.querySelectorAll('#comm_form_attached_images img').length; i++) { if(document.querySelectorAll('#comm_form_attached_images img')[i].src.includes('i.imgur.com')) imgs.push(document.querySelectorAll('#comm_form_attached_images img')[i].src); else { document.querySelector('#comm_form_attached_images').innerHTML = ''; window.alert('There has been a corrupted image that you have uploaded. Please reupload your images again.'); corrupted = true; break; } } if(corrupted) return false; else return imgs; } else return false; } function checkCategory() { let elem = q('pCategory'); if (elem.selectedIndex == 0) return false; else return elem.value; } const file = document.getElementById("comm_imgupload1") file.addEventListener("change", ev => { document.querySelector('#uploadImg').style.pointerEvents = 'none'; document.querySelector('#uploadImg').style.opacity = '0.3'; document.querySelector('#post_btn').style.pointerEvents = 'none'; document.querySelector('#post_btn').style.opacity = '0.3'; if (ev.target.files.length == 0) { document.querySelector('#uploadImg').style.pointerEvents = 'auto'; document.querySelector('#uploadImg').style.opacity = '1'; document.querySelector('#post_btn').style.pointerEvents = 'auto'; document.querySelector('#post_btn').style.opacity = '1'; } const formdata = new FormData() for (i = 0; i < ev.target.files.length; i++) { formdata.append("image", ev.target.files[0]) fetch("https://api.imgur.com/3/image/", { method: "post", headers: { Authorization: "Client-ID 7804a29d3ccda1c" }, body: formdata }).then(data => data.json()).then(data => { document.querySelector('#uploadImg').style.pointerEvents = 'auto'; document.querySelector('#uploadImg').style.opacity = '1'; document.querySelector('#post_btn').style.pointerEvents = 'auto'; document.querySelector('#post_btn').style.opacity = '1'; let img = document.createElement('img'); img.src = data.data.link; img.setAttribute('style', 'display: inline-block; margin: 5px; width: 150px !important'); document.querySelector('#comm_form_attached_images').appendChild(img); }) } }); function sendMessage(payload, webhookUrl) { const data = typeof payload === 'string' ? { content: payload } : payload; return new Promise((resolve, reject) => { fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }) .then((response) => { if (!response.ok) { reject(new Error("Could not send message: ${response.status}")); } resolve(); }) .catch((error) => { console.error(error); reject(error); }); }); } </script>