This repository has been archived by the owner on Nov 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdjbuy.js
74 lines (74 loc) · 3.11 KB
/
djbuy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
javascript:(function () {
"use strict";
var to_int = function (str) {
return parseInt(str.replace(/,/g, ""), 10);
},
sum = function (jQuery_obj) {
var result = 0;
jQuery_obj.each(function () {
result += to_int(this.innerHTML);
});
return result;
},
about = "\n\n\n\nDJBuy 1.4.2, https://github.com/chingc/DJBuy",
my_location = location.hostname + location.pathname,
shop_music = /djmaxcrew\.com\/maxshop\/shop_music_detail\.asp/.test(my_location),
shop_item = /djmaxcrew\.com\/maxshop\/shop_dj_(icon|title).asp/.test(my_location),
message,
points,
points_needed,
purchase_id,
purchase_success;
if (shop_music || shop_item) {
points = to_int($(".login_maxpoint .point_blue").text());
points_needed = shop_music ? sum($(".i_check:enabled").siblings("font")) : sum($(".point > font"));
message = "Available Max Points: " + points + "\nMax Points Needed: " + points_needed + "\n\n";
if (points_needed === 0) {
alert(message + "Nothing to buy. Returning..." + about);
history.back();
} else if (points_needed > points) {
alert(message + "Not enought Max Points to buy everything." + about);
} else {
if (confirm(message + "Proceed with purchase?" + about)) {
purchase_id = [];
purchase_success = true;
if (shop_music) {
$(".i_check:enabled").each(function () {
purchase_id.push(this.value);
});
$.ajax({
url: "http://" + location.hostname + "/maxshop/ProcShopMusic.asp?si=" + purchase_id.join("|"),
async: false
}).done(function () {
alert("Purchased!" + about);
}).fail(function () {
alert("Unable to make purchase." + about);
});
history.back();
} else {
$("li[onclick]").each(function () {
var pid;
pid = /moveShopItemConfirm\('(\w+)'\)/.exec(this.onclick);
if (pid) {
purchase_id.push(pid[1])
}
});
$.each(purchase_id, function (i, value) {
$.ajax({
url: "http://" + location.hostname + "/maxshop/ProcShopItem.asp?i=" + value,
async: false
}).fail(function () {
purchase_success = false;
});
});
if (purchase_success) {
alert("Items purchased!" + about);
} else {
alert("Unable to make one or more purchases." + about);
}
location.reload();
}
}
}
}
}());