dr124

Geoguessr custom avatar - two images

Jun 30th, 2022 (edited)
4,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function fileToBase64(f) {
  2.   function getBase64(file) {
  3.     const reader = new FileReader()
  4.     return new Promise(resolve => {
  5.       reader.onload = ev => {
  6.         resolve(ev.target.result)
  7.       }
  8.       reader.readAsDataURL(file)
  9.     });
  10.   }
  11.   return await getBase64(f);
  12. }
  13.  
  14.  
  15. function openFile(){
  16.   var input = document.createElement('input');
  17.   input.type = 'file';
  18.   return new Promise(resolve => {
  19.     input.onchange = async (e) => {
  20.       resolve(await fileToBase64(e.target.files[0]));
  21.     }
  22.     input.click();
  23.   });
  24. }
  25.  
  26. function sendRequest(dataMug, dataFull){
  27.   return new Promise((resolve, reject) => {
  28.     var xmlhttp = new XMLHttpRequest();   // new HttpRequest instance
  29.     var theUrl = 'https://www.geoguessr.com/api/v4/avatar';
  30.     xmlhttp.open("POST", theUrl);
  31.     xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  32.     xmlhttp.onload = () => {
  33.     if (xmlhttp.status >= 200 && xmlhttp.status < 300) {
  34.         resolve(xmlhttp.response);
  35.       } else {
  36.         reject(xmlhttp.statusText);
  37.       }
  38.     };
  39.     xmlhttp.onerror = () => reject(xmlhttp.statusText);
  40.     xmlhttp.send(JSON.stringify({
  41.       "skin": 6,
  42.       "equippedIds": [],
  43.       "mugshotPin": dataMug,
  44.       "fullBodyPin": dataFull,
  45.     }));
  46.   });
  47. }
  48.  
  49. console.log("please select to images: first one is mugshot (face only), the second one is full body");
  50. console.log("if you want to use same image then please select it twice!");
  51. console.log("====");
  52.  
  53. console.log("SELECT FACE IMAGE - preferably square");
  54. let mugshot = await openFile();
  55.  
  56. console.log("SELECT FULLBODY IMAGE - preferably ratio like 1:1.38 ");
  57. let fullbody = await openFile();
  58.  
  59. await sendRequest(mugshot, fullbody);
  60.  
  61. console.log("DONE");
  62. window.location.reload(true);
  63.  
Add Comment
Please, Sign In to add comment