From 97c03d3be0e2e8a7b75c4c658b4ba9c96723955c Mon Sep 17 00:00:00 2001 From: Ching Chow Date: Mon, 22 Apr 2013 16:45:57 -0400 Subject: [PATCH] DJBuy 1.4! --- CHANGELOG.md | 6 +++- README.md | 2 ++ djbuy.js | 79 ++++++++++++++++++++++++++++++++++++---------------- djbuy.min.js | 2 +- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 522086b..04025e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ +## 1.4: 2013-04-22 +- Added: Purchase an entire page of icons, plates, and titles at a time. + + ## 1.3: 2013-04-22 - Code cleanup. ## 1.2: 2012-12-07 -- Fixed: Purchase failure when using djmaxcrew.com instead of www.djmaxcrew.com. +- Fixed: Purchase failure when "www" is left out of the hostname. ## 1.1: 2012-11-04 diff --git a/README.md b/README.md index 148c09a..bd991b7 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ A bookmarklet to facilitate purchases from the DJMAX Technika 3 Max Point Shop. Buying items is a simple but tedious task. It takes too many clicks and way more time than it should. DJBuy is designed to purchase all charts of a song with a single click, avoiding extra clicking and page redirects. +Introduced in DJBuy 1.4 is the ability to purchase an entire page of icons, plates, and titles at a time! + ## Screenshots diff --git a/djbuy.js b/djbuy.js index 6778e41..3fb2ae7 100644 --- a/djbuy.js +++ b/djbuy.js @@ -1,42 +1,73 @@ -javascript:(/* DJBuy, version 1.3, https://github.com/smwst/DJBuy */ function () { +javascript:(function () { 'use strict'; var to_int = function (str) { return parseInt(str.replace(/,/g, ''), 10); }, - match = /djmaxcrew\.com\/maxshop\/shop_music_detail\.asp\?m=[01]&i=[a-zA-Z0-9]+/, + 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, chingc.tumblr.com', + 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; - if (match.test(location.hostname + location.pathname + location.search)) { + purchase_id, + purchase_success; + if (shop_music || shop_item) { points = to_int($('.login_maxpoint .point_blue').text()); - points_needed = (function () { - var sum = 0; - $('.i_check:enabled').siblings('font').each(function () { - sum += to_int(this.innerHTML); - }); - return sum; - }()); + 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...'); + alert(message + 'Nothing to buy. Returning...' + about); history.back(); } else if (points_needed > points) { - alert(message + 'Not enought Max Points to buy everything.'); + alert(message + 'Not enought Max Points to buy everything.' + about); } else { - if (confirm(message + 'Proceed with purchase?')) { + if (confirm(message + 'Proceed with purchase?' + about)) { purchase_id = []; - $('.i_check:enabled').each(function () { - purchase_id.push(this.value); - }); - $.ajax({ - url: 'http://' + location.hostname + '/maxshop/ProcShopMusic.asp?si=' + purchase_id.join('|') - }).done(function () { - alert('Purchased! You have ' + (points - points_needed) + ' Max Points left.\n\nReturning...'); + 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(); - }).fail(function () { - alert('Unable to make purchase.\n\nReload the page or try again later.'); - }); + } 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(); + } } } } diff --git a/djbuy.min.js b/djbuy.min.js index 0b5892f..b82acbe 100644 --- a/djbuy.min.js +++ b/djbuy.min.js @@ -1 +1 @@ -javascript:(/* DJBuy, version 1.2, https://github.com/smwst/DJBuy */ function(){"use strict";var e=/djmaxcrew\.com\/maxshop\/shop_music_detail\.asp\?m=[01]&i=[a-zA-Z0-9]+/,t,n,r,i;if(e.test(location.hostname+location.pathname+location.search)){t=parseInt($(".login_maxpoint .point_blue").text().replace(/,/g,""),10);n=function(){var e=0;$.map($.map($(".i_check:enabled").siblings("font"),function(e){return parseInt(e.innerHTML.replace(/,/g,""),10)}),function(t){e+=t});return e}();r="Available Max Points: "+t+"\nMax Points Needed: "+n+"\n\n";i=[];if(n===0){alert(r+"Nothing to buy. Returning...");history.back()}else if(n>t){alert(r+"Not enought Max Points to buy everything.")}else{if(confirm(r+"Proceed with purchase?")){$.map($(".i_check:enabled"),function(e){i.push(e.value,"|")});i.pop();$.ajax({url:"http://"+location.hostname+"/maxshop/ProcShopMusic.asp?si="+i.join("")}).done(function(){alert("Purchased! You have "+(t-n)+" Max Points left.\n\nReturning...");history.back()}).fail(function(){alert("Unable to make purchase.\n\nReload the page or try again later.")})}}}})() \ No newline at end of file +javascript:(function(){"use strict";var e=function(e){return parseInt(e.replace(/,/g,""),10)},t=function(t){var n=0;t.each(function(){n+=e(this.innerHTML)});return n},n="\n\n\n\nDJBuy 1.4, chingc.tumblr.com",r=location.hostname+location.pathname,i=/djmaxcrew\.com\/maxshop\/shop_music_detail\.asp/.test(r),s=/djmaxcrew\.com\/maxshop\/shop_dj_(icon|title).asp/.test(r),o,u,a,f,l;if(i||s){u=e($(".login_maxpoint .point_blue").text());a=i?t($(".i_check:enabled").siblings("font")):t($(".point > font"));o="Available Max Points: "+u+"\nMax Points Needed: "+a+"\n\n";if(a===0){alert(o+"Nothing to buy. Returning..."+n);history.back()}else if(a>u){alert(o+"Not enought Max Points to buy everything."+n)}else{if(confirm(o+"Proceed with purchase?"+n)){f=[];l=true;if(i){$(".i_check:enabled").each(function(){f.push(this.value)});$.ajax({url:"http://"+location.hostname+"/maxshop/ProcShopMusic.asp?si="+f.join("|"),async:false}).done(function(){alert("Purchased!"+n)}).fail(function(){alert("Unable to make purchase."+n)});history.back()}else{$("li[onclick]").each(function(){var e;e=/moveShopItemConfirm\('(\w+)'\)/.exec(this.onclick);if(e){f.push(e[1])}});$.each(f,function(e,t){$.ajax({url:"http://"+location.hostname+"/maxshop/ProcShopItem.asp?i="+t,async:false}).fail(function(){l=false})});if(l){alert("Items purchased!"+n)}else{alert("Unable to make one or more purchases."+n)}location.reload()}}}}})() \ No newline at end of file