Greasy Fork is available in English.
try to take over the world!
当前为
// ==UserScript==
// @name Training School Tools
// @namespace np
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://www.neopets.com/pirates/academy.phtml?type=status
// @match http://www.neopets.com/island/training.phtml?type=status
// @match http://www.neopets.com/island/fight_training.phtml?type=status
// @grant GM_getValue
// @grant GM_setValue
// @require https://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==
const PIN = 4365; // set to 0 if you don't have PIN enabled for SDB
const url = location.href;
const itemID = {
"One Dubloon Coin": "12755",
"Two Dubloon Coin": "12756",
"Five Dubloon Coin": "12757",
"Mau Codestone": "7458",
"Tai-Kai Codestone": "7459",
"Lu Codestone": "7460",
"Vo Codestone": "7461",
"Eo Codestone": "7462",
"Main Codestone": "7463",
"Zei Codestone": "7464",
"Orn Codestone": "7465",
"Har Codestone": "7466",
"Bri Codestone": "7467",
"Mag Codestone": "22208",
"Vux Codestone": "22209",
"Cui Codestone": "22210",
"Kew Codestone": "22211",
"Sho Codestone": "22212",
"Zed Codestone": "22213"
};
//$("b:contains('Current Course Status')").after('<br><br><button id="completeAll" type="button">Complete all</button>');
const process_url = location.pathname.replace(/\/(?!.+\/)/g, "/process_");
// Get list of all pets
let pets = [];
$("b").filter(function () {
return this.innerHTML.includes(" (Level ");
}).each(function (index, element) {
const petName = $(element).text().split(" (Level")[0];
pets.push(petName);
});
// Replace complete course button
let 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('<button id="complete-' + petName + '" type="button">Complete!</button>');
$("#complete-" + petName).on("click", function () {
$(this).prop("disabled", true);
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('<br><button class="getItems" type="button">Get items from SDB</button>');
});
// dubloon
$("b:contains(' Dubloon Coin')").each(function (index, element) {
$(element).parent().parent().before('<tr><td style="text-align: center" colspan="2"><button class="getItems" type="button">Get from SDB</button></td></tr>');
});
// 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").each(function (index, element) {
let codestone = $(element).text();
items.push(codestone);
});
}
if (url.includes("/pirates/")) {
let dubloon = $(element).parentsUntil("table").eq(2).find("b").text();
items.push(dubloon);
}
(async () => $(this).html(await getItemsFromSDB(items)))();
});
});
/* ------- Functions ------- */
function completeCourse(element, pet) {
const $this = $(element);
$.ajax({
type: "POST",
url: process_url,
async: false,
data: {
"type": "complete",
"pet_name": pet
},
success: function (data, status, xhr) {
let stat = data.match(/increased (\w+)/)[1] || "error";
let bonus = data.includes("SUPER BONUS") ? parseInt(data.match(/SUPER BONUS - You went up (\d+) points/)[1]) : 0;
console.log({
"pet": pet,
"status": status,
"stat": stat,
"bonus": bonus
});
console.log(data);
let result = stat === "error" ? "error" : '<b style="color:green">Course complete!</b><br><br><span>+' + (1 + bonus) + ' ' + stat + '</span><br><br><button id="repeat-' + pet + '" type="button">Repeat this course</button>';
$this.parent().parent().html(result);
if (document.getElementById("repeat-" + pet)) {
$("#repeat-" + pet).on("click", function () {
$(this).prop("disabled", true);
startCourse(pet, stat)
});
}
}
});
}
function startCourse(pet, course) {
$.ajax({
type: "POST",
url: process_url,
async: false,
data: {
"type": "start",
"course_type": course,
"pet_name": pet
},
success: function (data, status, xhr) {
let error = data.includes("Error:") ? "Error: " + data.split("<b>Error: </b>")[1].split("</div>")[0] : "successful";
console.log({
"Pet": pet,
"Course": course,
"Status": error
});
location.reload();
}
});
}
function getItemsFromSDB(array) {
return new Promise(resolve => {
let postData = {};
let itemCount = {};
for (let i = 0; i < array.length; i++) {
let id = itemID[array[i]];
if (!itemCount[id]) {
itemCount[id] = 0;
}
itemCount[id]++;
for (let item in itemCount) {
if (itemCount[item] > 0) {
postData["back_to_inv[" + id + "]"] = itemCount[item];
}
}
}
postData["category"] = "0";
postData["offset"] = "0";
if (PIN) {
postData["pin"] = PIN;
}
$.ajax({
type: "POST",
url: "/process_safetydeposit.phtml?checksub=scan",
async: false,
data: postData,
success: function () {
resolve("Done!");
}
});
})
}
//<center><IMG src="http://pets.neopets.com/cpn/PETNAME/1/2.png" width="150" height="150" border="0"><br><b>Woohoo!</b><p>Congratulations! <b>PETNAME</b> now has increased Defence!!!<p><form action='fight_training.phtml' method='post'><input type='submit' value='Go Back to the Secret Ninja Training School'></form>
//<center><IMG src="http://pets.neopets.com/cpn/PETNAME/1/2.png" width="150" height="150" border="0"><br><b>Woohoo!</b><p>Congratulations! <b>PETNAME</b> now has increased Strength!!!<p><b>*** SUPER BONUS - You went up 2 points!! ***</b><p><form action='academy.phtml' method='get'><input type='submit' value='Back to the Swashbuckling Academy'></form>