`);
// Create quick course table
let tableRows = ``;
for (let pet in stats) {
const thisPet = stats[pet];
const withinLvlRange =
url.includes("island/fight_training") || // Only pets >= Lv250 will appear on the page anyway
url.includes("island/training") && thisPet["Lvl"] <= 250 ||
url.includes("pirates/academy") && thisPet["Lvl"] <= 40;
if ($(`b:contains(${pet})`).text().includes("is not on a course") &&
withinLvlRange === true) {
tableRows += `
${pet}
${thisPet["Lvl"]}
${thisPet["Str"]}
${thisPet["Def"]}
${thisPet["Mov"]}
${thisPet["Hp"]}
`;
}
}
if (tableRows !== ``) {
$("#courseTable").show();
$("#tableHeader").after(tableRows);
$("#checkall input").each(function (index, element) {
const $this = $(element);
const stat = $this.attr("class").split("-")[1];
$this.on("change", function () {
if ($this.prop("checked")) {
$(":radio").filter(function () {
return this.value === stat;
}).each(function () {
$(this).prop("checked", true);
});
}
});
});
$("#reset-all").on("click", function () {
$(".courses :radio").each(function (index, element) {
$(element).prop("checked", false);
});
});
$("#train-all").on("click", function () {
$(".courses input").each(function (index, element) {
$(element).prop("disabled", true); // disable all radio buttons
});
let training = [];
$(".courses tbody").find("input:checked:not([name='checkall'])").each(function (index, element) {
const pet = $(element).attr("name").split("-")[1];
const stat = $(element).val();
training.push([pet, stat]);
});
(async () => {
print(`[1 / ${training.length}]
Processing...`)
for (let i = 0; i < training.length; i++) {
const pet = training[i][0];
const stat = training[i][1];
const result = await startCourse(pet, stat);
console.log(result);
print(`[${i + 1} / ${training.length}]
${result["Pet"]} (${result["Course"]}) :
${result["Status"]}`);
}
location.replace(url);
})();
});
}
// Replace complete course button
const forms = $("form[action*='process_']"); // get all available "Complete course!" forms
for (let i = 0; i < forms.length; i++) {
let petName = forms.eq(i).find("input[name='pet_name']").val();
let completeButton = forms.eq(i).find(":submit[value='Complete Course!']");
completeButton.replaceWith(``);
$(`#complete-${petName}`).on("click", function () {
completeCourse(this, petName);
});
}
// Add button to get dubloons/codestones from SDB
// codestone
$("a[href*='_training.phtml?type=pay&pet_name=']").each(function (index, element) {
//let petName = $(element).attr("href").split("&pet_name=")[1];
let $p = $(element).next("p");
$p.before(' ');
});
// dubloon
$("b:contains(' Dubloon Coin')").each(function (index, element) {
$(element).parent().parent().before('
');
});
// Handler
$(".getItems").each(function (index, element) {
$(element).on("click", function () {
$(this).prop("disabled", true);
let items = [];
if (url.includes("/island/")) {
$(element).next("p").find("b:contains('Codestone')").each(function (index, element) {
const codestone = $(element).text();
items.push(codestone);
});
}
if (url.includes("/pirates/")) {
const dubloon = $(element).parentsUntil("table").eq(2).find("b").text();
items.push(dubloon);
}
(async () => $(this).html(await getItemsFromSDB(items)))();
});
});
/********************************
*
* All quick links
*
********************************/
// Get all items
let getAllItems = [];
$(".getItems").each(function (index, element) {
// Codestones
if (url.includes("/island/")) {
$(element).next("p").find("b:contains('Codestone')").each(function (index2, element2) {
const codestone = $(element2).text();
getAllItems.push(codestone);
});
}
// Dubloons
if (url.includes("/pirates/")) {
const dubloon = $(element).parent().parent().parent().find("b:contains('Dubloon Coin')").html();
getAllItems.push(dubloon);
}
});
$("#getAll-button").on("click", function () {
if (!getAllItems.length) {
window.alert("No items to retrieve!");
return false;
}
$(this).prop("disabled", true);
let printItems = {};
for (let i = 0; i < getAllItems.length; i++) {
if (!printItems[getAllItems[i]]) {
printItems[getAllItems[i]] = 0;
}
printItems[getAllItems[i]]++;
}
const itemList = JSON.stringify(printItems).replace(/,/g, " ").replace(/[{}"']/g, "").replace(/:(\d)/g, " (x$1)");
(async () => {
$(this).html(await getItemsFromSDB(getAllItems));
print(`[${getTime()}]
Retrieved items:
${itemList}
If some ${url.includes("/island/") ? "codestones" : "dubloons"} were not retrieved, you may not have enough in your Safety Deposit Box.`);
})();
});
// Complete all courses
$("#completeAll-button").on("click", function () {
const numButtons = $(".completeButton").length;
if (!numButtons) {
window.alert("No courses to complete!");
return false;
}
$(this).prop("disabled", true);
print(`[${getTime()}]
Processing...`);
(async () => {
let printText = `[${getTime()}]
`;
for (let i = 0; i < numButtons; i++) {
const thisButton = $(".completeButton")[i];
const petName = $(thisButton).attr("id").split("-")[1];
const {pet, stat, bonus} = await completeCourse(thisButton, petName);
printText += `${pet} : +${bonus} ${stat} `;
}
print(printText);
})();
});
// Pay all courses
$("#payAll-button").on("click", function () {
let payees = [];
if (url.includes("/island/training.phtml")) {
$("a[href*='process_training.phtml']").each(function (index, element) {
const pet = $(element).attr("href").split("name=")[1];
payees.push(pet);
});
} else if (url.includes("/pirates/academy.phtml")) {
$(":submit[value='Pay']").each(function (index, element) {
const pet = $(element).prev().prev().val();
payees.push(pet);
});
} else if (url.includes("/island/fight_training.phtml")) {
$("a[href*='process_fight_training.phtml?type=pay']").each(function (index, element) {
const pet = $(element).attr("href").split("name=")[1];
payees.push(pet);
});
}
if (payees.length) {
$(this).prop("disabled", true);
(async () => {
for (let i = 0; i < payees.length; i++) {
const pet = payees[i];
// print(`[${i + 1} / ${payees.length}]