Greasy Fork

Agma Animation Macro

Customize your animation hotkey using chat commands!

当前为 2019-08-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         Agma Animation Macro
// @namespace    http://tampermonkey.net/
// @version      v0.4.0
// @description  Customize your animation hotkey using chat commands!
// @author       Nuke
// @match        http://agma.io/
// @grant        none
// ==/UserScript==

var aam_storage = {};

$(document).ready(function () {
    if (!localStorage.getItem("aam_storage")) {
        aam_storage.slot1 = "";
        aam_storage.slot2 = "";
        aam_storage.slot3 = "";
        localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
    } else {
        var parsed = JSON.parse(localStorage.getItem('aam_storage'));
        aam_storage.slot1 = parsed.slot1;
        aam_storage.slot2 = parsed.slot2;
        aam_storage.slot3 = parsed.slot3;
    }
    if (!localStorage.getItem("aam_changelog") || localStorage.getItem("aam_changelog") !== "v0.4.0") {
        localStorage.setItem("aam_changelog", "v0.4.0");
        changelog();
    }
})

function changelog() {
    swal({
        title: 'Changelog: v0.4.0',
        text: 'Recoded most of the code.<br>Added a command to reset all slots at once.<br>Added a command to set an animation on all slots at once.<br>Type <code>/help</code> for info!',
        html: true
    })
}

var slots = [1, 2, 3];
var slot;
var slot1;
var slot2;
var slot3;
var animations = ["spin", "flip", "shake", "jump", "wacky"];
var inputVal = "";
var input = $("#chtbox");
var result = $("#result");
var newAni = "";

input.on("keydown", function (e) {
    inputVal = input.val();
    if ($(this).is(":focus") && e.keyCode == '13') {
        if (inputVal.indexOf('/settings') > -1) {
            if (inputVal.length === 11) {
                if (inputVal[10] == '*') {
                    aam_storage.slot1 = "";
                    aam_storage.slot2 = "";
                    aam_storage.slot3 = "";
                    localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
                    swal({
                        title: 'Slots Reset',
                        text: 'All slots have been reset!',
                        type: 'success'
                    })
                } else if ($.inArray(JSON.parse(inputVal[10]), slots) > -1) {
                    slot = slots[$.inArray(JSON.parse(inputVal[10]), slots)];
                    switch (slot) {
                        case 1:
                            aam_storage.slot1 = "";
                            swal({
                                title: 'Slot Reset',
                                text: 'Slot 1 has been reset!',
                                type: 'success'
                            })
                            break;
                        case 2:
                            aam_storage.slot2 = "";
                            swal({
                                title: 'Slot Reset',
                                text: 'Slot 2 has been reset!',
                                type: 'success'
                            })
                            break;
                        case 3:
                            aam_storage.slot3 = "";
                            swal({
                                title: 'Slot Reset',
                                text: 'Slot 3 has been reset!',
                                type: 'success'
                            })
                            break;
                    } localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
                } else if ($.inArray(JSON.parse(inputVal[10]), slots) == -1) {
                    console.log("max slots")
                }
                $("#chtbox").val("")
            } else if (inputVal.length === 9) {
                slot1 = aam_storage.slot1;
                slot2 = aam_storage.slot2;
                slot3 = aam_storage.slot3;
                if (slot1 == "") {
                    slot1 = "empty"
                }
                if (slot2 == "") {
                    slot2 = "empty"
                }
                if (slot3 == "") {
                    slot3 = "empty"
                }
                swal({
                    title: 'Settings',
                    text: 'Your current slot values are:<br><b>Slot 1:</b><code>' + slot1 + '</code><br><b>Slot 2:</b><code>' + slot2 + '</code><br><b>Slot 3:</b><code>' + slot3 + '</code>',
                    html: true
                })
                $("#chtbox").val("")
            } else if (!(inputVal.length > 17)) {
                for (var i = 0; i < animations.length; i++) {
                    if (inputVal.indexOf(animations[i]) != -1) {
                        newAni = animations[i];
                        if (inputVal[10] == '*') {
                            aam_storage.slot1 = newAni;
                            aam_storage.slot2 = newAni;
                            aam_storage.slot3 = newAni;
                            localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
                            swal({
                                title: 'Slots Changed',
                                text: 'All slots have been changed to <code>' + newAni + '</code>',
                                html: true,
                                type: 'success'
                            })
                        } else if ($.inArray(JSON.parse(inputVal[10]), slots) > -1) {
                            slot = slots[$.inArray(JSON.parse(inputVal[10]), slots)];
                            switch (slot) {
                                case 1:
                                    aam_storage.slot1 = newAni;
                                    swal({
                                        title: 'Slot Changed',
                                        text: 'Slot 1\'s value has been changed to <code>' + newAni + '</code>',
                                        html: true,
                                        type: 'success'
                                    })
                                    break;
                                case 2:
                                    aam_storage.slot2 = newAni;
                                    swal({
                                        title: 'Slot Changed',
                                        text: 'Slot 2\'s value has been changed to <code>' + newAni + '</code>',
                                        html: true,
                                        type: 'success'
                                    })
                                    break;
                                case 3:
                                    aam_storage.slot3 = newAni;
                                    swal({
                                        title: 'Slot Changed',
                                        text: 'Slot 3\'s value has been changed to <code>' + newAni + '</code>',
                                        html: true,
                                        type: 'success'
                                    })
                                    break;
                            } localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
                        }
                    }
                }
                $("#chtbox").val("")
            }
        } if (inputVal.indexOf('/help') > -1) {
            swal({
                title: 'Information',
                text: '<code>/settings</code> | Shows your current settings<br><code>/settings {slot number}</code> | Resets given slot<br><code>/settings {slot number} (animation)</code> | Sets given animation on given slot<br><code>/settings *</code> | Resets all slots</br><code>/settings * (animation)</code> Sets given animation on all slots',
                html: true
            })
            $("#chtbox").val("")
        }
    }
})

function aamAnimate() {
    var items = JSON.parse(localStorage.getItem("aam_storage"));
    $("#chtbox").val('/' + items.slot1 + items.slot2 + items.slot3).focus();
}

$(document).on("keydown", function (e) {
    if (e.keyCode == '192' && !e.shitKey) {
        e.preventDefault();
        aamAnimate();
    }
})