PDA

View Full Version : [GM/TM] I need a script doctor



MadameNova
04-25-2019, 08:44 PM
I found this neopian shop discounter someone made, but it does not seem to work. Could someone check it out when they get a chance?


// ==UserScript==
// name Neopets: Reduce Shop Prices
// namespace userscripts-mirror.org
// Description Reduce prices in shop by specific percentage
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

$total = 0;
$items = 0;
var debug = false;

$("input[name^='cost']").each(function(){
$amount = $(this).parent().parent().find('td:eq(2)').text();
$amount = Number($amount);
$thisItem = 0;
for(var i = 1;i <= $amount;i++){
$thisItem = $thisItem + Number($(this).val());
}
$total = $thisItem + $total;
$items++;
});

// alert($test);

$total = $total.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");

GM_log($total);
GM_log($items);

$("center:contains('Items Stocked')").append("<br>Total : <b>" + $total + " NP</b>");

// code to insert checkbox
// Round to nearest 100?<input type='checkbox' name='round' checked><br>

$("tbody:contains('Piccy'):last tr:contains('Remove All'):last").before("<tr><td colspan='8' bgcolor='#dddd77' align='center'><input type='text' value='10%' id='discount' size='3'><input type='button' value='Discount Prices' id='discountUpdate'></td></tr>");

// alert("Shop Total: "+$total+"NP");

$("#discountUpdate").click(function(){
$discount = $('#discount').val();
$discount = $discount.replace('%','');
if($discount < 100){
$discount = $discount / 100;
// check if checkbox is checked, if yes, round discount, if not, continue normally
if(debug){GM_log($discount);}
$("input[name^='cost']").each(function(){
$currentPrice = $(this).val();
if(debug){GM_log("Current: " + $currentPrice);}
if($currentPrice != 0){
$newPrice = Math.round($currentPrice - ($currentPrice * $discount));
if(debug){GM_log("New (discounted by 10%): " + $newPrice);}
$(this).val($newPrice);
}
});
alert("Prices discounted! Remember to update the shop!");
}else{
alert("Please input a percent under 100");
}
});

RealisticError
04-25-2019, 08:59 PM
This seems to work correctly, it's an old script and was using out of date GM functions




// ==UserScript==
// name Neopets: Reduce Shop Prices
// namespace userscripts-mirror.org
// Description Reduce prices in shop by specific percentage
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

$total = 0;
$items = 0;
var debug = false;

$("input[name^='cost']").each(function(){
$amount = $(this).parent().parent().find('td:eq(2)').text();
$amount = Number($amount);
$thisItem = 0;
for(var i = 1;i <= $amount;i++){
$thisItem = $thisItem + Number($(this).val());
}
$total = $thisItem + $total;
$items++;
});

// alert($test);

$total = $total.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");

console.log($total);
console.log($items);

$("center:contains('Items Stocked')").append("<br>Total : <b>" + $total + " NP</b>");

// code to insert checkbox
// Round to nearest 100?<input type='checkbox' name='round' checked><br>

$("tbody:contains('Piccy'):last tr:contains('Remove All'):last").before("<tr><td colspan='8' bgcolor='#dddd77' align='center'><input type='text' value='10%' id='discount' size='3'><input type='button' value='Discount Prices' id='discountUpdate'></td></tr>");

// alert("Shop Total: "+$total+"NP");

$("#discountUpdate").click(function(){
$discount = $('#discount').val();
$discount = $discount.replace('%','');
if($discount < 100){
$discount = $discount / 100;
// check if checkbox is checked, if yes, round discount, if not, continue normally
if(debug){console.log($discount);}
$("input[name^='cost']").each(function(){
$currentPrice = $(this).val();
if(debug){console.log("Current: " + $currentPrice);}
if($currentPrice != 0){
$newPrice = Math.round($currentPrice - ($currentPrice * $discount));
if(debug){console.log("New (discounted by 10%): " + $newPrice);}
$(this).val($newPrice);
}
});
alert("Prices discounted! Remember to update the shop!");
}else{
alert("Please input a percent under 100");
}
});

Bat
04-25-2019, 09:04 PM
[Only registered and activated users can see links]



// ==UserScript==
// name Neopets: Reduce Shop Prices
// namespace userscripts-mirror.org
// Description Reduce prices in shop by specific percentage
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

$total = 0;
$items = 0;
var debug = false;

$("input[name^='cost']").each(function(){
$amount = $(this).parent().parent().find('td:eq(2)').text();
$amount = Number($amount);
$thisItem = 0;
for(var i = 1;i <= $amount;i++){
$thisItem = $thisItem + Number($(this).val());
}
$total = $thisItem + $total;
$items++;
});

// alert($test);

$total = $total.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");

GM_log($total);
GM_log($items);

$("center:contains('Items Stocked')").append("<br>Total : <b>" + $total + " NP</b>");

// code to insert checkbox
// Round to nearest 100?<input type='checkbox' name='round' checked><br>

$("tbody:contains('Piccy'):last tr:contains('Remove All'):last").before("<tr><td colspan='8' bgcolor='#dddd77' align='center'><input type='text' value='10%' id='discount' size='3'><input type='button' value='Discount Prices' id='discountUpdate'></td></tr>");

// alert("Shop Total: "+$total+"NP");

$("#discountUpdate").click(function(){
$discount = $('#discount').val();
$discount = $discount.replace('%','');
if($discount < 100){
$discount = $discount / 100;
// check if checkbox is checked, if yes, round discount, if not, continue normally
if(debug){GM_log($discount);}
$("input[name^='cost']").each(function(){
$currentPrice = $(this).val();
if(debug){GM_log("Current: " + $currentPrice);}
if($currentPrice != 0){
$newPrice = Math.round($currentPrice - ($currentPrice * $discount));
if(debug){GM_log("New (discounted by 10%): " + $newPrice);}
$(this).val($newPrice);
}
});
alert("Prices discounted! Remember to update the shop!");
}else{
alert("Please input a percent under 100");
}
});

Ha ha! Well met, RealisticError! I was a few seconds slower than you!

RealisticError
04-25-2019, 09:16 PM
Ha ha! Well met, RealisticError! I was a few seconds slower than you!

It's always a fun race to the finish with you, Odd ;)

MadameNova
04-26-2019, 07:32 PM
Merci beaucoup � vous deux!

I run a lot of sales, which means not having to do this by hand anymore is a good thing.