Created
August 9, 2013 23:45
-
-
Save cassidoo/6198248 to your computer and use it in GitHub Desktop.
If you have "product" JSON objects, you can use this to parse the title and search Amazon and Ebay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getResults = function(/*successResponse*/){ | |
// Dummy data examples | |
var obj = [{ | |
"title": "MICHAEL Michael Kors Women\u0027s 3/4 Double-Breasted Hooded Trench,Khaki,Medium", | |
"imagePath": "http://static8.superfish.com/images_np/shared/sys_v2/images/un/30-03-2011/un-pricegrabber24-03-2011_03-25- 20/_Request_1132/source_125/category_4230_UNIFIED_COATS_W/detail/342122213_342122259", | |
"internalId": "342122259", | |
"price": "175.00$", | |
"merchantName": "Amazon", | |
"productId": "12345" | |
}, | |
{ | |
"title": "New Balance Men's MR993 Running Shoe", | |
"imagePath": "http://ecx.images-amazon.com/images/I/51sYrPr805L.jpg", | |
"internalId": "342122259", | |
"price": "134.95$", | |
"merchantName": "Amazon", | |
"productId": "12345" | |
}]; | |
var urlAmazon ='http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords='; | |
var urleBay ='http://www.ebay.com/sch/i.html?_nkw='; | |
var html = ''; | |
for (var i=0; i<obj.length; i++) | |
{ | |
var newTitle = obj[i].title; | |
var urlSearch = parseTitle(newTitle); | |
urlAmazon += urlSearch; | |
urleBay += urlSearch; | |
var priceCut = '$' + obj[i].price.replace(/\$/, ''); | |
html += '<div class="indEntry">'; | |
html += '<h3 class="title">' + obj[i].title + '</h3>'; | |
html += '<img src="' + obj[i].imagePath + '" />'; | |
html += '<div class="resultinfo">'; | |
html += '<p>' + priceCut + '</p>'; | |
html += '<a href="'+urlAmazon+'">'; | |
html += '<input type="button" value="Amazon Results" /> </a>'; | |
html += '<a href="'+urleBay+'">'; | |
html += '<input type="button" value="eBay Results"/> </a>'; | |
html += '</div></div>'; | |
} | |
document.getElementById("results").innerHTML = html; | |
} | |
var parseTitle = function(stringy) | |
{ | |
var space = '+'; | |
var comma = '%2C'; | |
var andpers = '%26'; | |
var pound = '%23'; | |
var at = '%40'; | |
stringy = stringy.replace(/\s/g, space); | |
stringy = stringy.replace(/\,/g, comma); | |
stringy = stringy.replace(/\&/g, andpers); | |
stringy = stringy.replace(/\#/g, pound); | |
stringy = stringy.replace(/\@/g, at); | |
return stringy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment