[Neopets] Grave Danger Random Diver

Adds a button that sends a random petpet off to the catacombs, without any equipment.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         [Neopets] Grave Danger Random Diver
// @namespace    https://greasyfork.org/en/scripts/487970
// @version      0.4
// @description  Adds a button that sends a random petpet off to the catacombs, without any equipment.
// @author       Piotr Kardovsky
// @match        https://www.neopets.com/halloween/gravedanger/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=neopets.com
// @grant        none
// @license      MIT
// @require      http://code.jquery.com/jquery-latest.min.js
// @run-at       document-end
// ==/UserScript==
var $ = window.jQuery;

const GDU = "https://www.neopets.com/halloween/gravedanger/";

(function() {
    'use strict';
    let pname = null;
    let doAgain = () => {
            $.post(GDU, {'again':'1'}, (r) => {
                let match = r.match(/(petpets: \{"[\s\S]+"\}),/)[0];
                match = "{\"petpets\"" + match.substring(7, match.length-1) + "}";
                let getGD = JSON.parse(match);
                let pArr = Object.keys(getGD.petpets);
                pname = pArr[Math.floor(Math.random() * (pArr.length - 1) + 1)];
                //console.log(pArr, pname);
                setTimeout( () => {
                    $.post(GDU, {'neopet':pname, 'equipped':"0"}, (m) => { location.reload(); });
                }, Math.floor(Math.random() * 400 + 600))
            });
    }

    let rndAgn = $('<button/>').addClass('button-default__2020 button-blue__2020 rndAgnBtn').css({'margin':'0px auto', 'width':'50%'}).text('Dive again with a random Petpet!').on('click', (e) => { e.preventDefault(); doAgain(); });

    $(document).ready(() => {
        $('#gdSelection .select:contains("Choose a Petpet!")').before(rndAgn);
        $('.gdForm').prepend($('<br/>'),rndAgn.clone(true, true));
    });
})();