Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(jQuery) {
- /* Make the array of products. */
- // initialize the array
- var products = [];
- // for each product...
- jQuery('li.panel a').each(function(i, el) {
- var $el = jQuery(el);
- var product = {};
- product['name'] = $el.find('h3.b3').text();
- // product['link'] = "http://www.nintendo.com" + $el.find('li.panel a').attr('href');
- product['fullPrice'] = $el.find('p.price.strike-through').text().replace(/[$ ]/g, '');
- product['price'] = $el.find('p.price.sale-price').text().replace(/[$ ]/g, '');
- product['discount'] = parseInt((product.fullPrice - product.price) * 100 / product.fullPrice);
- product['platforms'] = $el.find('p.b4').text();
- // $el.find('.platforms i').each(function(i, el) {
- // product['platforms'].push($(this).attr('class'));
- // });
- product['type'] = "normal";
- // push the product into the array of products
- products.push(product);
- });
- /* Sort the products based on name.
- * Change 'name' to 'price' to sort by price, etc.
- */
- function sortFunc(a, b) {
- if (a.name > b.name) {
- return 1;
- }
- if (a.name < b.name) {
- return -1;
- }
- // a must be equal to b
- return 0;
- }
- products.sort(sortFunc);
- /* Make the Markdown-style table. */
- // arrange these columns however you want, but be sure to change it in the for-loop
- var appendable = "Platform | Title | Sale Price | List Price | Discount"
- appendable += "\n:-----|:-----:|:-------:|:----:|:-----:|---------:"
- for (var i = 0; i < products.length; i++) {
- // append a newline character to start the next row
- appendable += "\n";
- // append the platforms to the table
- appendable += ""+products[i].platforms+"| "
- // append the name to the table
- appendable += ""+products[i].name+"| "
- // append the price to the table
- appendable += "$"+products[i].price+"| "
- // append the price to the table
- appendable += "$"+products[i].fullPrice
- // append the discount to the table, making sure to re-add the hyphen and percentage sign
- appendable += " | " + "-"+products[i].discount+"%";
- }
- /* Append the table to the console. */
- console.log(appendable);
- } else {
- console.err("This script requires jQuery, which isn't on this page. :(");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement