Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     if(jQuery) {
  2.       /* Make the array of products. */
  3.       // initialize the array
  4.       var products = [];
  5.       // for each product...
  6.       jQuery('li.panel a').each(function(i, el) {
  7.         var $el = jQuery(el);
  8.         var product = {};
  9.         product['name'] = $el.find('h3.b3').text();
  10.  //       product['link'] = "http://www.nintendo.com" + $el.find('li.panel a').attr('href');
  11.         product['fullPrice'] = $el.find('p.price.strike-through').text().replace(/[$ ]/g, '');
  12.         product['price'] = $el.find('p.price.sale-price').text().replace(/[$ ]/g, '');
  13.         product['discount'] = parseInt((product.fullPrice - product.price) * 100 / product.fullPrice);
  14.         product['platforms'] = $el.find('p.b4').text();
  15.  //       $el.find('.platforms i').each(function(i, el) {
  16.  //         product['platforms'].push($(this).attr('class'));
  17.  //       });
  18.         product['type'] = "normal";
  19.         // push the product into the array of products
  20.         products.push(product);
  21.       });
  22.      
  23.       /* Sort the products based on name.
  24.        * Change 'name' to 'price' to sort by price, etc.
  25.        */
  26.       function sortFunc(a, b) {
  27.         if (a.name > b.name) {
  28.           return 1;
  29.         }
  30.         if (a.name < b.name) {
  31.           return -1;
  32.         }
  33.         // a must be equal to b
  34.         return 0;
  35.       }
  36.       products.sort(sortFunc);
  37.      
  38.       /* Make the Markdown-style table. */
  39.       // arrange these columns however you want, but be sure to change it in the for-loop
  40.      
  41.       var appendable = "Platform | Title | Sale Price | List Price | Discount"
  42.       appendable += "\n:-----|:-----:|:-------:|:----:|:-----:|---------:"
  43.       for (var i = 0; i < products.length; i++) {
  44.         // append a newline character to start the next row
  45.         appendable += "\n";
  46.         // append the platforms to the table
  47.         appendable += ""+products[i].platforms+"| "
  48.         // append the name to the table
  49.         appendable += ""+products[i].name+"| "
  50.         // append the price to the table   
  51.         appendable += "$"+products[i].price+"| "
  52.         // append the price to the table   
  53.         appendable += "$"+products[i].fullPrice
  54.         // append the discount to the table, making sure to re-add the hyphen and percentage sign
  55.         appendable += " | " + "-"+products[i].discount+"%";
  56.       }
  57.      
  58.       /* Append the table to the console. */
  59.       console.log(appendable);
  60.     } else {
  61.       console.err("This script requires jQuery, which isn't on this page. :(");
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement