Results 1 to 5 of 5

Thread: [GM/TM] I need a script doctor

  1. #1

    Joined
    Oct 2017
    Posts
    119
    Thanks
    352
    Thanked
    51/30
    DL/UL
    18/0
    Mentioned
    9 times
    Time Online
    2d 19h N/A
    Avg. Time Online
    1m

    [GM/TM] I need a script doctor

    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?

    Code:
    // ==UserScript==
    // @(you need an account to see links)        Neopets: Reduce Shop Prices
    // @(you need an account to see links)space   userscripts-mirror.org
    // @(you need an account to see links)cription Reduce prices in shop by specific percentage
    // @include     (you need an account to see links)
    // @include    (you need an account to see links)
    // @include    (you need an account to see links)
    // @require    (you need an account to 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");
        }
    });

  2. #2
    RealisticError's Avatar
    Joined
    Jul 2018
    Posts
    1,629
    Userbars
    26
    Thanks
    899
    Thanked
    2,282/840
    DL/UL
    36/0
    Mentioned
    133 times
    Time Online
    55d 3h 58m
    Avg. Time Online
    37m
    This seems to work correctly, it's an old script and was using out of date GM functions



    Code:
    // ==UserScript==
    //  @(you need an account to see links)        Neopets: Reduce Shop Prices
    //  @(you need an account to see links)space   userscripts-mirror.org
    //  @(you need an account to see links)cription Reduce prices in shop by specific percentage
    // @include     (you need an account to see links)
    // @include    (you need an account to see links)
    // @include    (you need an account to see links)
    // @require    (you need an account to 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");
        }
    });

  3. The Following 2 Users Say Thank You to RealisticError For This Useful Post:

    Bat (04-25-2019),MadameNova (04-26-2019)

  4. #3
    *squeak*
    Bat's Avatar
    Joined
    Nov 2012
    Posts
    4,037
    Userbars
    153
    Thanks
    2,147
    Thanked
    46,344/3,558
    DL/UL
    34/1
    Mentioned
    1,751 times
    Time Online
    644d 29m
    Avg. Time Online
    3h 42m
    Hey @(you need an account to see links)! This script was missing the "@grant GM_log" header required to write log entries, which resulted in an error that stopped it from fully rendering. Here's an update:

    Code:
    // ==UserScript==
    //   @(you need an account to see links)        Neopets: Reduce Shop Prices
    //   @(you need an account to see links)space   userscripts-mirror.org
    //   @(you need an account to see links)cription Reduce prices in shop by specific percentage
    // @grant       GM_log
    // @include     (you need an account to see links)
    // @include    (you need an account to see links)
    // @include    (you need an account to see links)
    // @require    (you need an account to 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, @(you need an account to see links)! I was a few seconds slower than you!

  5. The Following 2 Users Say Thank You to Bat For This Useful Post:

    MadameNova (04-26-2019),RealisticError (04-25-2019)

  6. #4
    RealisticError's Avatar
    Joined
    Jul 2018
    Posts
    1,629
    Userbars
    26
    Thanks
    899
    Thanked
    2,282/840
    DL/UL
    36/0
    Mentioned
    133 times
    Time Online
    55d 3h 58m
    Avg. Time Online
    37m
    Quote Originally Posted by Odd View Post

    Ha ha! Well met, @(you need an account to see links)! I was a few seconds slower than you!
    It's always a fun race to the finish with you, @(you need an account to see links)

  7. The Following User Says Thank You to RealisticError For This Useful Post:

    Bat (04-25-2019)

  8. #5

    Joined
    Oct 2017
    Posts
    119
    Thanks
    352
    Thanked
    51/30
    DL/UL
    18/0
    Mentioned
    9 times
    Time Online
    2d 19h N/A
    Avg. Time Online
    1m
    Merci beaucoup � vous deux!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •