Skip to content

Commit

Permalink
Fix for new axie ID URL format
Browse files Browse the repository at this point in the history
  • Loading branch information
freakitties committed Oct 14, 2021
1 parent 4f7ddd8 commit d130070
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,26 @@ function checkStatus(res) {
if (res.ok) {
return res;
} else {
throw Exception("Failed to get axie details: " + res);
throw "Failed to get axie details: " + res;
}
}

function getAxieIdFromURL(url) {
let pattern = /\/axie\/(\d+)/;
let m = url.match(pattern);
if (m) {
return parseInt(m[1]);
}
return -1;
}

//Assume we are on https://marketplace.axieinfinity.com/profile/inventory/axie
async function getAccountFromProfile() {
let axieAnchors = document.querySelectorAll("a[href^='/axie/']");
if (axieAnchors.length > 0) {
let anc = axieAnchors[0];
let axieId = parseInt(anc.href.substring(anc.href.lastIndexOf("/") + 1));
let axieId = getAxieIdFromURL(anc.href);
if (axieId == -1) return null;
let axie = await getAxieInfoMarket(axieId);
//this will return the 0x formatted ronin address
return axie.owner;
Expand Down Expand Up @@ -556,7 +566,8 @@ TODO: add support for breeding window

//single axie (axieDetail page). Added mouseover handler to Stats text
if (currentURL.match(/https:\/\/marketplace\.axieinfinity\.com\/axie\/\d+/)) {
let axieId = parseInt(currentURL.substring(currentURL.lastIndexOf("/") + 1));
let axieId = getAxieIdFromURL(currentURL);
if (axieId == -1) throw "Bad Axie ID";
let axie;
axie = await getAxieInfoMarket(axieId);

Expand Down Expand Up @@ -587,7 +598,9 @@ TODO: add support for breeding window
for (let i = 0; i < axieAnchors.length; i++) {
let anc = axieAnchors[i];
let div = anc.firstElementChild;
let axieId = parseInt(anc.href.substring(anc.href.lastIndexOf("/") + 1));
let axieId = getAxieIdFromURL(anc.href);
if (axieId == -1) continue;

if (!(axieId in axies)) {
//get all axies on the page and break
debugLog("getting axies");
Expand All @@ -605,8 +618,8 @@ debugLog(axies);
for (let i = 0; i < axieAnchors.length; i++) {
let anc = axieAnchors[i];
let div = anc.firstElementChild;
let axieId = parseInt(anc.href.substring(anc.href.lastIndexOf("/") + 1));

let axieId = getAxieIdFromURL(anc.href);
if (axieId == -1) continue;
let axie;
if (!(axieId in axies)) {
axie = await getAxieInfoMarket(axieId);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Freak's Axie Extension",
"version": "1.5.1",
"version": "1.5.2",
"description": "An extension to help play Axie Infinity.",
"permissions": ["activeTab", "declarativeContent", "storage"],
"icons": {
Expand Down

0 comments on commit d130070

Please sign in to comment.