<style> div.pInf, div.brdCmb, h1.pTtl, .hot-items-buttons, header.header, .blogMn { display: none !important; } </style> <div style="text-align: center;"> <br /><br /><br /> <p id='logs' class="ui ignored message"> </p> <br /> <form id='form_username' style='display: none; text-align: left; margin: auto; width: max-content;' action="javascript:finishSetup();"> <div class="ui label"> <img class="ui right spaced avatar image" src="https://semantic-ui.com/images/avatar/small/elliot.jpg" /> Finish everything before getting started! </div> <br /> <img src="https://mystickermania.com/cdn/stickers/games/the-battle-cats-nerd-cat-512x512.png" style="width: 200px;" /> <br /> <p class="ui label red large">Create username <span id="username-status" class="ui small white label" style="cursor: pointer;" >Checking..</span ></p> <br /> <div class="ui large inverted input focus"> <input minlength="6" oninput="this.value = this.value.replace(/\s/g, '')" id="username-input" required="" type="text" placeholder="Username" /> </div> <br /> <p class="ui large red label">Your birthday</p> <div class="ui mini inverted input focus"> <input id="birthday-input" type="date" required /> </div> <br /> <p class="ui large red label">Country</p> <span id="country-status" class="ui small blue label" style="cursor: pointer;" >Unknown</span > <br /> <p class="ui large red label">Gender</p> <select id="gender_option" class="ui large label"> <option value="M" class="ui large white label">MALE</option> <option value="F" class="ui large white label">FEMALE</option> </select> <br /> <br /><br /> <button id='submit_btn' type="submit" class="ui big red button">Finish Setup</button> </form> <br /><br /><br /> </div> <script type="module"> document.querySelector('.mainWrp').style.backgroundImage = "linear-gradient(to bottom, rgb(0,0,0,0.5) 10%, rgb(0,0,0,0.9) 90%), url(\"https://i.imgur.com/0zBhK8y.png\")"; document.querySelector('.mainWrp').style.backgroundRepeat = "no-repeat;" document.querySelector('.mainWrp').style.backgroundSize = "cover"; document.querySelector('.mainWrp').style.backgroundPosition = "center center"; document.querySelector('.mainWrp').style.backgroundAttachment = "fixed"; let url = window.location.href; url = decodeURI(url); let country_code = ''; let username_exists = false; (async() => { let data = await fetch('https://api.country.is'); data = await data.json(); if (data && data.country) { document.querySelector('#country-status').innerHTML = "<img src='https://flagsapi.com/" + data.country + "/shiny/64.png'/> " + data.country; country_code = data.country; } else country_code = "Anonymous"; })(); window.addEventListener('load', async() => { await initFunctions(['supabase']); let btn = document.getElementById('signup_btn'); let user_input = document.getElementById('username-input'); let username_status = document.getElementById('username-status'); user_input.addEventListener('keyup', async() => { let { data, error } = await supabase.from('users').select('username').eq('username', user_input.value); if (error) { window.alert(JSON.stringify(error)); return; } if (data.length > 0) { username_status.innerHTML = "⚠️ Not Available"; username_status.setAttribute('class', 'ui large label'); return; } else { username_status.innerHTML = "✅ Available"; username_status.setAttribute('class', 'ui large label'); } }); let session = await supabase.auth.getSession(); // verify if the access to the page is valid // assume the url is stored at DOM if (session.data && session.data.session) { if (!url.includes(session.data.session.access_token) && !session.data) { window.location.href = "https://storehaccounts.blogspot.com/"; return; } else { // verify if this user is already in the table if (session.data.session.user.email) { let { data, error } = await supabase.from('users').select('email', 'prof_img').eq('email', session.data.session.user.email); if (error) { window.alert("Error encountered from select: " + JSON.stringify(error)); return; } if (data.length > 0) { document.querySelector('#logs').innerHTML = "You are all setup bro! Redirecting you to home."; window.location.href = 'https://storehaccounts.blogspot.com/'; return; } } } } else window.location.href = 'https://storehaccounts.blogspot.com/p/sign-in-with-storehaccounts.html'; document.querySelector('#form_username').style.display = 'block'; document.querySelector('#logs').innerHTML = "When signing in with your account, you don't need any passwords, just use your social media logins.<br /><br />But you need to create your username"; window.finishSetup = async() => { setTimeout(async() => { let { data } = await supabase.from('users').select('username').eq('username', user_input.value); document.getElementById('form_username').style = 'text-align: left; margin: auto; width: max-content; opacity: 0.7; pointer-events: none'; if (data.length > 0) { document.getElementById('form_username').style = 'text-align: left; margin: auto; width: max-content; opacity: 1; pointer-events: auto'; window.alert("Your username is no longer available. Try new :)"); return; } let username = document.getElementById('username-input').value; let birthday = document.getElementById('birthday-input').value; let country = (country_code == "" ? country_code = "Anonymous" : country_code = country_code); let gender = document.getElementById('gender_option').value; let session_data = await supabase.auth.getSession(); if (!session_data) return; let metadata = session_data.data.session.user.user_metadata; let email = metadata.email; let prof_img = !metadata.picture ? 'https://i.imgur.com/8OkNVL4.png' : metadata.picture; let { error } = await supabase.from('users').insert({ created_at: "now()", username: username, gender: gender, country: country, rank_id: 1, email: email, birthday: birthday, prof_img: prof_img }); if (error) { window.alert(JSON.stringify(error)); console.log(JSON.stringify(error)); document.getElementById('form_username').style = 'text-align: left; margin: auto; width: max-content; opacity: 1; pointer-events: auto'; return; } window.alert("Your account is now setup!"); window.location.href = 'https://storehaccounts.blogspot.com/'; }, 500); } }, false); </script>