Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function fileToBase64(f) {
- function getBase64(file) {
- const reader = new FileReader()
- return new Promise(resolve => {
- reader.onload = ev => {
- resolve(ev.target.result)
- }
- reader.readAsDataURL(file)
- });
- }
- return await getBase64(f);
- }
- function openFile(){
- var input = document.createElement('input');
- input.type = 'file';
- return new Promise(resolve => {
- input.onchange = async (e) => {
- resolve(await fileToBase64(e.target.files[0]));
- }
- input.click();
- });
- }
- function sendRequest(dataMug, dataFull){
- return new Promise((resolve, reject) => {
- var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
- var theUrl = 'https://www.geoguessr.com/api/v4/avatar';
- xmlhttp.open("POST", theUrl);
- xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- xmlhttp.onload = () => {
- if (xmlhttp.status >= 200 && xmlhttp.status < 300) {
- resolve(xmlhttp.response);
- } else {
- reject(xmlhttp.statusText);
- }
- };
- xmlhttp.onerror = () => reject(xmlhttp.statusText);
- xmlhttp.send(JSON.stringify({
- "skin": 6,
- "equippedIds": [],
- "mugshotPin": dataMug,
- "fullBodyPin": dataFull,
- }));
- });
- }
- console.log("please select to images: first one is mugshot (face only), the second one is full body");
- console.log("if you want to use same image then please select it twice!");
- console.log("====");
- console.log("SELECT FACE IMAGE - preferably square");
- let mugshot = await openFile();
- console.log("SELECT FULLBODY IMAGE - preferably ratio like 1:1.38 ");
- let fullbody = await openFile();
- await sendRequest(mugshot, fullbody);
- console.log("DONE");
- window.location.reload(true);
Add Comment
Please, Sign In to add comment