// ==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
// @downloadURL 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.
Added a command to reset all slots at once.
Added a command to set an animation on all slots at once.
Type /help
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:
Slot 1:' + slot1 + '
Slot 2:' + slot2 + '
Slot 3:' + slot3 + '
',
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 ' + newAni + '
',
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 ' + newAni + '
',
html: true,
type: 'success'
})
break;
case 2:
aam_storage.slot2 = newAni;
swal({
title: 'Slot Changed',
text: 'Slot 2\'s value has been changed to ' + newAni + '
',
html: true,
type: 'success'
})
break;
case 3:
aam_storage.slot3 = newAni;
swal({
title: 'Slot Changed',
text: 'Slot 3\'s value has been changed to ' + newAni + '
',
html: true,
type: 'success'
})
break;
} localStorage.setItem("aam_storage", JSON.stringify(aam_storage));
}
}
}
$("#chtbox").val("")
}
} if (inputVal.indexOf('/help') > -1) {
swal({
title: 'Information',
text: '/settings
| Shows your current settings
/settings {slot number}
| Resets given slot
/settings {slot number} (animation)
| Sets given animation on given slot
/settings *
| Resets all slots/settings * (animation)
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();
}
})