Skip to content

Commit

Permalink
Support reverse part search
Browse files Browse the repository at this point in the history
  • Loading branch information
freakitties committed Dec 22, 2021
1 parent c7ef57b commit 0adc2c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 3 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 => {
Expand Down
31 changes: 25 additions & 6 deletions contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0adc2c4

Please sign in to comment.