Skip to content

Commit

Permalink
make max tickets work with bulk play
Browse files Browse the repository at this point in the history
  • Loading branch information
menma1234 committed Jul 27, 2021
1 parent 161caf9 commit 4504cce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GBF Item Magic",
"version": "1.5.7",
"version": "1.5.8",
"minimum_chrome_version": "40.0",
"manifest_version": 2,
"description": "Provides various tools for saving time in Granblue Fantasy when working with items.",
Expand Down
20 changes: 17 additions & 3 deletions src/content/gacha.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@
});
}

function doBulkPull(id) {
function doBulkPull(id, bulkPullCost) {
var url = buildUrl(mungeRestUrl("/" + eventName + "/rest/gacha/bulk_play"), uid);

var req = new XMLHttpRequest();
req.open("POST", url);

req.onload = function() {
if(max) {
max -= bulkPullCost;
}
contentAction(id);
};

Expand Down Expand Up @@ -137,8 +140,10 @@
}

var id = parseInt(single.getAttribute("data-id"));
if(empty && max === null && doc.getElementsByClassName("prt-bulk-blink").length) {
doBulkPull(id);
var bulkPullCost = getBulkPullTicketCost(doc);
var shouldBulkPull = doc.getElementsByClassName("prt-bulk-blink").length && (max === null || max >= bulkPullCost);
if(empty && shouldBulkPull) {
doBulkPull(id, bulkPullCost);
return;
}

Expand Down Expand Up @@ -266,6 +271,15 @@
return doc.getElementsByClassName("txt-current-point")[0].innerHTML;
}
}

function getBulkPullTicketCost(doc) {
var bulkCostDiv = doc.querySelector(".bulk .txt-medal-cost");
if(bulkCostDiv) {
return parseInt(doc.querySelector(".bulk .txt-medal-cost").textContent);
}

return null;
}

function hasResetButton(doc) {
return doc.getElementsByClassName("btn-reset").length > 0;
Expand Down

0 comments on commit 4504cce

Please sign in to comment.