From 0adc2c491c5121779aa8581542d4e2fc97d33664 Mon Sep 17 00:00:00 2001 From: freak Date: Wed, 22 Dec 2021 01:57:01 -0800 Subject: [PATCH] Support reverse part search --- background.js | 6 +++--- contentScript.js | 31 +++++++++++++++++++++++++------ manifest.json | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/background.js b/background.js index a3be877..ea9768f 100644 --- a/background.js +++ b/background.js @@ -23,7 +23,7 @@ chrome.runtime.onInstalled.addListener(function() { }); function getAxieInfoMarket(id, sendResponse) { - fetch("https://axieinfinity.com/graphql-server-v2/graphql?r=freak", {"headers":{"content-type":"application/json"},"body":"{\"operationName\":\"GetAxieDetail\",\"variables\":{\"axieId\":\"" + parseInt(id) + "\"},\"query\":\"query GetAxieDetail($axieId: ID!) {\\n axie(axieId: $axieId) {\\n ...AxieDetail\\n __typename\\n }\\n}\\n\\nfragment AxieDetail on Axie {\\n id\\n name\\n genes\\n owner\\n birthDate\\n bodyShape\\n class\\n sireId\\n sireClass\\n matronId\\n matronClass\\n stage\\n title\\n breedCount\\n level\\n figure {\\n atlas\\n model\\n image\\n __typename\\n }\\n parts {\\n ...AxiePart\\n __typename\\n }\\n stats {\\n ...AxieStats\\n __typename\\n }\\n auction {\\n ...AxieAuction\\n __typename\\n }\\n ownerProfile {\\n name\\n __typename\\n }\\n children {\\n id\\n name\\n class\\n image\\n title\\n stage\\n __typename\\n }\\n __typename\\n}\\n\\nfragment AxiePart on AxiePart {\\n id\\n name\\n class\\n type\\n stage\\n abilities {\\n ...AxieCardAbility\\n __typename\\n }\\n __typename\\n}\\n\\nfragment AxieCardAbility on AxieCardAbility {\\n id\\n name\\n attack\\n defense\\n energy\\n description\\n backgroundUrl\\n effectIconUrl\\n __typename\\n}\\n\\nfragment AxieStats on AxieStats {\\n hp\\n speed\\n skill\\n morale\\n __typename\\n}\\n\\nfragment AxieAuction on Auction {\\n startingPrice\\n endingPrice\\n startingTimestamp\\n endingTimestamp\\n duration\\n timeLeft\\n currentPrice\\n currentPriceUSD\\n suggestedPrice\\n seller\\n listingIndex\\n __typename\\n}\\n\"}","method":"POST"}) + fetch("https://graphql-gateway.axieinfinity.com/graphql?r=freak", {"headers":{"content-type":"application/json"},"body":"{\"operationName\":\"GetAxieDetail\",\"variables\":{\"axieId\":\"" + parseInt(id) + "\"},\"query\":\"query GetAxieDetail($axieId: ID!) {\\n axie(axieId: $axieId) {\\n ...AxieDetail\\n __typename\\n }\\n}\\n\\nfragment AxieDetail on Axie {\\n id\\n name\\n genes\\n owner\\n birthDate\\n bodyShape\\n class\\n sireId\\n sireClass\\n matronId\\n matronClass\\n stage\\n title\\n breedCount\\n level\\n figure {\\n atlas\\n model\\n image\\n __typename\\n }\\n parts {\\n ...AxiePart\\n __typename\\n }\\n stats {\\n ...AxieStats\\n __typename\\n }\\n auction {\\n ...AxieAuction\\n __typename\\n }\\n ownerProfile {\\n name\\n __typename\\n }\\n children {\\n id\\n name\\n class\\n image\\n title\\n stage\\n __typename\\n }\\n __typename\\n}\\n\\nfragment AxiePart on AxiePart {\\n id\\n name\\n class\\n type\\n stage\\n abilities {\\n ...AxieCardAbility\\n __typename\\n }\\n __typename\\n}\\n\\nfragment AxieCardAbility on AxieCardAbility {\\n id\\n name\\n attack\\n defense\\n energy\\n description\\n backgroundUrl\\n effectIconUrl\\n __typename\\n}\\n\\nfragment AxieStats on AxieStats {\\n hp\\n speed\\n skill\\n morale\\n __typename\\n}\\n\\nfragment AxieAuction on Auction {\\n startingPrice\\n endingPrice\\n startingTimestamp\\n endingTimestamp\\n duration\\n timeLeft\\n currentPrice\\n currentPriceUSD\\n suggestedPrice\\n seller\\n listingIndex\\n __typename\\n}\\n\"}","method":"POST"}) .then(response => { response.json().then(result => { let axie = result.data.axie; @@ -44,9 +44,9 @@ function getAxieBriefList(address, page, sort, auctionType, criteria, sendRespon if (formattedAddress != null) { formattedAddress = "\"" + address + "\""; } - fetch("https://axieinfinity.com/graphql-server-v2/graphql?r=freak", { + fetch("https://graphql-gateway.axieinfinity.com/graphql?r=freak", { "headers": {"content-type": "application/json"}, - "body": "{\"operationName\":\"GetAxieBriefList\",\"variables\":{\"from\":" + from + ",\"size\":24,\"sort\":\"" + sort + "\",\"auctionType\":\"" + auctionType + "\",\"owner\":" + formattedAddress + ",\"criteria\":" + JSON.stringify(criteria) + "},\"query\":\"query GetAxieBriefList($auctionType: AuctionType, $criteria: AxieSearchCriteria, $from: Int, $sort: SortBy, $size: Int, $owner: String) {\\n axies(auctionType: $auctionType, criteria: $criteria, from: $from, sort: $sort, size: $size, owner: $owner) {\\n total\\n results {\\n ...AxieBrief\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment AxieBrief on Axie {\\n id\\n genes\\n owner\\n name\\n stage\\n class\\n breedCount\\n image\\n title\\n stats {\\n ...AxieStats\\n __typename\\n }\\n battleInfo {\\n banned\\n __typename\\n }\\n auction {\\n currentPrice\\n currentPriceUSD\\n __typename\\n }\\n parts {\\n id\\n name\\n class\\n type\\n specialGenes\\n __typename\\n }\\n __typename\\n}\\nfragment AxieStats on AxieStats {\\n hp\\n speed\\n skill\\n morale\\n __typename\\n}\\n\\n\"}", + "body": "{\"operationName\":\"GetAxieBriefList\",\"variables\":{\"from\":" + from + ",\"size\":24,\"sort\":\"" + sort + "\",\"auctionType\":\"" + auctionType + "\",\"owner\":" + formattedAddress + ",\"criteria\":" + JSON.stringify(criteria) + ", \"filterStuckAuctions\":true},\"query\":\"query GetAxieBriefList($auctionType: AuctionType, $criteria: AxieSearchCriteria, $from: Int, $sort: SortBy, $size: Int, $owner: String, $filterStuckAuctions: Boolean) {\\n axies(auctionType: $auctionType, criteria: $criteria, from: $from, sort: $sort, size: $size, owner: $owner, filterStuckAuctions: $filterStuckAuctions) {\\n total\\n results {\\n ...AxieBrief\\n __typename\\n }\\n __typename\\n }\\n}\\n\\nfragment AxieBrief on Axie {\\n id\\n genes\\n owner\\n name\\n stage\\n class\\n breedCount\\n image\\n title\\n stats {\\n ...AxieStats\\n __typename\\n }\\n battleInfo {\\n banned\\n __typename\\n }\\n auction {\\n currentPrice\\n currentPriceUSD\\n __typename\\n }\\n parts {\\n id\\n name\\n class\\n type\\n specialGenes\\n __typename\\n }\\n __typename\\n}\\nfragment AxieStats on AxieStats {\\n hp\\n speed\\n skill\\n morale\\n __typename\\n}\\n\\n\"}", "method": "POST" }) .then(response => { diff --git a/contentScript.js b/contentScript.js index 015db9b..22338fc 100644 --- a/contentScript.js +++ b/contentScript.js @@ -27,8 +27,8 @@ const PROBABILITIES = {d: 0.375, r1: 0.09375, r2: 0.03125}; const parts = ["eyes", "mouth" ,"ears", "horn", "back", "tail"]; const MAX_QUALITY = 6 * (PROBABILITIES.d + PROBABILITIES.r1 + PROBABILITIES.r2); const MAX_RUN_RETRIES = 30; -const OPTIONS_MAP = {"class": "classes", "part": "parts", "bodyShape": "bodyShapes", "stage": "stages", "mystic": "numMystic"}; -const SEARCH_PARAMS = ["class", "stage", "breedCount", "mystic", "pureness", "region", "title", "part", "bodyShape", "hp", "speed", "skill", "morale"]; +const OPTIONS_MAP = {"class": "classes", "part": "parts", "bodyShape": "bodyShapes", "stage": "stages", "mystic": "numMystic", "excludeParts": "parts"}; +const SEARCH_PARAMS = ["class", "stage", "breedCount", "mystic", "pureness", "region", "title", "part", "bodyShape", "hp", "speed", "skill", "morale", "excludeParts", "purity"]; var notReadyCount = 0; var currentURL = window.location.href; @@ -376,7 +376,8 @@ debugLog("Account: " + address); auctionType = a[0]; } - let criteria = {"region":null,"parts":null,"bodyShapes":null,"classes":null,"stages":null,"numMystic":null,"pureness":null,"title":null,"breedCount":null,"hp":[],"skill":[],"speed":[],"morale":[]}; //"breedable":null, + excludedParts = []; + let criteria = {"region":null,"parts":null,"bodyShapes":null,"classes":null,"stages":null,"numMystic":null,"pureness":null,"purity":null,"title":null,"breedCount":null,"hp":[],"skill":[],"speed":[],"morale":[]}; //"breedable":null, for (let sIdx=0; sIdx < SEARCH_PARAMS.length; sIdx++) { let option = SEARCH_PARAMS[sIdx]; let opts = getQueryParameters(option); @@ -386,21 +387,39 @@ debugLog("Account: " + address); continue; } let opt = []; - if (["stage", "breedCount", "mystic", "pureness", "hp", "speed", "skill", "morale"].indexOf(option) != -1) { + if (["stage", "breedCount", "mystic", "pureness", "hp", "speed", "skill", "morale", "purity"].indexOf(option) != -1) { for (let i=0; i < opts.length; i++) { opt.push(parseInt(opts[i])); } + opt.sort((a, b) => a - b); } else { for (let i=0; i < opts.length; i++) { if ("title" == option) { opt.push(opts[i].replace(/-/g, " ")); } else { - opt.push(opts[i]); + if (option == "excludeParts") { + opt.push("!" + opts[i]); + excludedParts.push(opts[i]); + } else { + opt.push(opts[i]); + } } } } if (option in OPTIONS_MAP) { - criteria[OPTIONS_MAP[option]] = opt; + if (["part", "excludeParts"].includes(option)) { + if (criteria[OPTIONS_MAP[option]]) { + combined = [...criteria[OPTIONS_MAP[option]], ...opt]; + for (let i=0; i < excludedParts.length; i++) { + combined = combined.filter(e => e !== excludedParts[i]); + } + criteria[OPTIONS_MAP[option]] = combined; + } else { + criteria[OPTIONS_MAP[option]] = opt; + } + } else { + criteria[OPTIONS_MAP[option]] = opt; + } } else { criteria[option] = opt; } diff --git a/manifest.json b/manifest.json index dd5211f..7c18fe2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,11 @@ { "name": "Freak's Axie Extension", - "version": "1.6.0", + "version": "1.6.1", "description": "An extension to help play Axie Infinity.", "permissions": ["activeTab", "declarativeContent", "storage"], "host_permissions": [ "https://marketplace.axieinfinity.com/*", - "https://axieinfinity.com/*" + "https://*.axieinfinity.com/*" ], "icons": { "16": "images/rep_icon16.png",