Neopets Active Pet Switcher

Adds neopets active pet switcher under active pet name

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Neopets Active Pet Switcher
// @namespace    shiftasterisk
// @version      0.1
// @description  Adds neopets active pet switcher under active pet name
// @author       You
// @match        http://www.neopets.com/*
// @grant        none
// ==/UserScript==

$('.sidebarHeader.medText').first().append('<div id="petSelector"><span id="loadPets">Load Pet Switcher</span></div>');
$('#loadPets').css({'cursor':'pointer'});

$('#loadPets').click(function() {
    getPetImages();
});

function getPetImages(){
    $.ajax(
        {url: 'http://www.neopets.com/quickref.phtml',
         async: false,
         success: function(result) {
             $('#petSelector').empty().append('<input type="checkbox" name="reload" id="reload"><label for="reload">Reload After Switch</label><input type="checkbox" name="showOpts" id="showOpts"><label for="showOpts">Show Pet Options</label>');
             $(result).find('.pet_toggler img').each(function() {
                 console.log($(this).attr('title'));
                 $(this).addClass('petImage').css({'margin':'5px'}).appendTo('#petSelector');
             });
             $(result).find('.active_pet .pet_menu_hide').attr('id','activePetOpts').css({'list-style':'none'}).hide().appendTo('#petSelector');
         }
    });
}

$(document).on('click', '.petImage', function() {
    reload = $('#reload').is(':checked');
    console.log("Setting " + $(this).attr('title') + " to active pet");
    $.ajax(
        {url: 'http://www.neopets.com/process_changepet.phtml?new_active_pet=' + $(this).attr('title'),
         async: false,
         success: function(result) {
             getPetImages();
             if(reload)
                 location.reload();
         }
    });
});

$(document).on('change', '#showOpts', function() {
    showOpts = $('#showOpts').is(':checked');
    if(showOpts)
        $('#activePetOpts').show();
    else
        $('#activePetOpts').hide();
});