Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onOpen(e){
- SpreadsheetApp.getUi().createMenu('AXIE')
- .addItem('Refresh Axies','axie')
- .addItem('Enlarge image', 'enlargeImage')
- .addToUi();
- }
- function axie() {
- const ss = SpreadsheetApp.getActiveSpreadsheet();
- const sheet = ss.getSheetByName('Axie');
- const axies = sheet.getRange(4, 1, sheet.getLastRow() - 3).getValues().flat();
- const requests = [];
- const output = [];
- const imageFormulas = [];
- axies.forEach(axie => {
- const query = {
- "operationName": "GetAxieDetail",
- "variables": {
- "axieId": axie
- },
- "query": "query GetAxieDetail($axieId: ID!) { axie(axieId: $axieId) { ...AxieDetail __typename }}fragment AxieDetail on Axie { id image class chain name genes owner birthDate bodyShape class sireId sireClass matronId matronClass stage title breedCount level figure { atlas model image __typename } parts { ...AxiePart __typename } stats { ...AxieStats __typename } auction { ...AxieAuction __typename } ownerProfile { name __typename } battleInfo { ...AxieBattleInfo __typename } children { id name class image title stage __typename } __typename}fragment AxieBattleInfo on AxieBattleInfo { banned banUntil level __typename}fragment AxiePart on AxiePart { id name class type specialGenes stage abilities { ...AxieCardAbility __typename } __typename}fragment AxieCardAbility on AxieCardAbility { id name attack defense energy description backgroundUrl effectIconUrl __typename}fragment AxieStats on AxieStats { hp speed skill morale __typename}fragment AxieAuction on Auction { startingPrice endingPrice startingTimestamp endingTimestamp duration timeLeft currentPrice currentPriceUSD suggestedPrice seller listingIndex state __typename}"
- }
- const config = {
- method: 'post',
- url: 'https://graphql-gateway.axieinfinity.com/graphql',
- headers: {
- 'Content-Type': 'application/json'
- },
- payload: JSON.stringify(query)
- };
- requests.push(config);
- });
- const responses = UrlFetchApp.fetchAll(requests);
- const objects = responses.map(res => {
- const data = JSON.parse(res.getContentText()).data.axie;
- imageFormulas.push([`=IF($B$1 = true,IMAGE("${data.image}"),)`]);
- const object = {
- Name: data.name,
- Stage: data.stage,
- Class: data.matronClass,
- Chain: data.chain,
- 'Breed Count': data.breedCount,
- Level: data.level,
- 'Auction USD': data.auction?.currentPriceUSD,
- Birthdate: new Date(data.birthDate * 1000).toISOString().split('T')[0],
- Shape: data.bodyShape,
- HP: data.stats.hp,
- Speed: data.stats.speed,
- Skill: data.stats.skill,
- Morale: data.stats.morale,
- Owner: data.ownerProfile?.name,
- Banned: data.battleInfo.banned
- }
- return object
- })
- objects.forEach((obj, index) => {
- if (index == 0){
- output.push(Object.keys(obj))
- }
- output.push(Object.values(obj))
- })
- sheet.getRange(3,2,sheet.getLastRow(),sheet.getLastColumn()).clearContent();
- sheet.getRange(3,2,output.length,output[0].length).setValues(output);
- sheet.getRange(3,sheet.getLastColumn()).setValue('Image');
- sheet.getRange(4,sheet.getLastColumn(),imageFormulas.length,1).setFormulas(imageFormulas);
- }
- function enlargeImage() {
- const formula = SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getFormula();
- const url = /IMAGE\(\"(.*?)\"/g.exec(formula)[1];
- const html = `
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- img {
- max-width: 100%;
- max-height: 100%;
- }
- </style>
- <base target="_top">
- </head>
- <body>
- <div class=img>
- <img src="${url}">
- </div>
- </body>
- </html>
- `
- SpreadsheetApp.getUi().showDialog(HtmlService.createHtmlOutput(html).setHeight(500).setWidth(800));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement