r4vpl

WISH.COM SEARCHER v2

Sep 25th, 2014
2,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //by R4v.pl, 2014 for Wykop.pl
  2.  
  3. //\/\/https:\/\/www.wish.com/api/search?start=0&query=test&price=&transform=true
  4.  
  5. var dupa;
  6. var ITEMS = [];
  7. var ITEMSsorted = [];
  8. function setMinAverage(array1, value) {
  9. var b = 0;
  10.     for (var i = 0, len = array1.length; i < len; i++){
  11.                 moreThan = false;
  12.                         if(array1[i]['product_rating']['rating'] >= value && array1[i]['product_rating']['rating_count'] > 0)
  13.                         moreThan = true;
  14.                    
  15.                        
  16.                 if(moreThan == true){
  17.                 ITEMS[b] = array1[i];
  18.                         b++;
  19.                 }
  20.                
  21.                
  22.                
  23.                 }
  24.                 return ITEMS;
  25. }
  26.  
  27. function setMinRating(array1, value) {
  28. var b = 0;
  29.     for (var i = 0, len = array1.length; i < len; i++){
  30.                 moreThan = false;
  31.                         if(array1[i]['product_rating']['rating_count'] >= value)
  32.                         moreThan = true;
  33.                    
  34.                        
  35.                 if(moreThan == true){
  36.                 ITEMS[b] = array1[i];
  37.                         b++;
  38.                 }
  39.                
  40.                
  41.                
  42.                 }
  43.                 return ITEMS;
  44. }
  45. function filtre(ITEMS){
  46. if (minAverage !=0) setMinAverage(ITEMS, minAverage);
  47. if (minRating !=0) setMinRating(ITEMS, minRating);
  48.  
  49. }
  50. function showHTML(array){
  51. var HTML ="";
  52. HTML += "<html><head>   <link href=\"\/\/netdna.bootstrapcdn.com\/bootstrap\/3.1.1\/css\/bootstrap.min.css\" rel=\"stylesheet\">";
  53. HTML += "<\/head><body> <script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.0\/jquery.min.js\"><\/script>";
  54. HTML += "    <script src=\"\/\/netdna.bootstrapcdn.com\/bootstrap\/3.1.1\/js\/bootstrap.min.js\"><\/script><style>";
  55. HTML += ".glyphicon { margin-right:5px; }";
  56. HTML += ".thumbnail";
  57. HTML += "{";
  58. HTML += "    margin-bottom: 20px;";
  59. HTML += "    padding: 0px;";
  60. HTML += "    -webkit-border-radius: 0px;";
  61. HTML += "    -moz-border-radius: 0px;";
  62. HTML += "    border-radius: 0px;";
  63. HTML += "}";
  64. HTML += "";
  65. HTML += ".item.list-group-item";
  66. HTML += "{";
  67. HTML += "    float: none;";
  68. HTML += "    width: 100%;";
  69. HTML += "    background-color: #fff;";
  70. HTML += "    margin-bottom: 10px;";
  71. HTML += "}";
  72. HTML += ".item.list-group-item:nth-of-type(odd):hover,.item.list-group-item:hover";
  73. HTML += "{";
  74. HTML += "    background: #428bca;";
  75. HTML += "}";
  76. HTML += "";
  77. HTML += ".item.list-group-item .list-group-image";
  78. HTML += "{";
  79. HTML += "    margin-right: 10px;";
  80. HTML += "}";
  81. HTML += ".item.list-group-item .thumbnail";
  82. HTML += "{";
  83. HTML += "    margin-bottom: 0px;";
  84. HTML += "}";
  85. HTML += ".item.list-group-item .caption";
  86. HTML += "{";
  87. HTML += "    padding: 9px 9px 0px 9px;";
  88. HTML += "}";
  89. HTML += ".item.list-group-item:nth-of-type(odd)";
  90. HTML += "{";
  91. HTML += "    background: #eeeeee;";
  92. HTML += "}";
  93. HTML += "";
  94. HTML += ".item.list-group-item:before, .item.list-group-item:after";
  95. HTML += "{";
  96. HTML += "    display: table;";
  97. HTML += "    content: \" \";";
  98. HTML += "}";
  99. HTML += "";
  100. HTML += ".item.list-group-item img";
  101. HTML += "{";
  102. HTML += "    float: left;";
  103. HTML += "}";
  104. HTML += ".item.list-group-item:after";
  105. HTML += "{";
  106. HTML += "    clear: both;";
  107. HTML += "}";
  108. HTML += ".list-group-item-text";
  109. HTML += "{";
  110. HTML += "    margin: 0 0 11px;";
  111. HTML += "}";
  112. HTML += "";
  113. HTML += "<\/style>";
  114. HTML += "<div class=\"container\">";
  115. HTML += "    <div class=\"well well-sm\">";
  116. HTML += "        <strong>Wyniki<\/strong>";
  117. HTML += "        <div class=\"btn-group\">";
  118. HTML += "            <a href=\"#\" id=\"list\" class=\"btn btn-default btn-sm\"><span class=\"glyphicon glyphicon-th-list\">";
  119. HTML += "            <\/span>Lista<\/a> <a href=\"#\" id=\"grid\" class=\"btn btn-default btn-sm\"><span";
  120. HTML += "                class=\"glyphicon glyphicon-th\"><\/span>Grid<\/a>";
  121. HTML += "        <\/div>";
  122. HTML += "    <\/div>";
  123. HTML += "    <div id=\"products\" class=\"row list-group\">";
  124.  
  125. for (var i = 0, len = array.length; i < len; i++){
  126. var TITLE = array[i]['name'];
  127. var IMG =array[i]['small_picture'];
  128. /*if (typeof array[i]['description'] === 'undefined') {
  129.    
  130. var DESCRIPTION = array[i]['name'];
  131. }
  132. else */ var DESCRIPTION = array[i]['name'];
  133. var PRICE =array[i]['commerce_product_info']['variations'][0]['price'] + " + " +  array[i]['commerce_product_info']['variations'][0]['shipping'] + " " +  array[i]['localized_value']['symbol'];
  134. var URL =array[i]['external_url'];
  135. HTML += "<div class=\"item  col-xs-4 col-lg-4\">";
  136. HTML += "            <div class=\"thumbnail\">";
  137. HTML += "                <img class=\"group list-group-image\" src=" + IMG  + " alt=\"\" \/>";
  138. HTML += "                <div class=\"caption\">";
  139. HTML += "                    <h4 class=\"group inner list-group-item-heading\">";
  140. HTML += "                        "+ TITLE + "<\/h4>";
  141. HTML += "                    <p class=\"group inner list-group-item-text\">";
  142. HTML += "                        " + DESCRIPTION + "<\/p>";
  143. HTML += "                    <div class=\"row\">";
  144. HTML += "                        <div class=\"col-xs-12 col-md-6\">";
  145. HTML += "                            <p class=\"lead\">";
  146. HTML += "                                " + PRICE + "<\/p>";
  147. HTML += "                        <\/div>";
  148. HTML += "                        <div class=\"col-xs-12 col-md-6\">";
  149. HTML += "                            <a class=\"btn btn-success\"  target=\"_blank\"  href=" + URL + ">Przejdź<\/a>";
  150. HTML += "                        <\/div>";
  151. HTML += "                    <\/div>";
  152. HTML += "                <\/div>";
  153. HTML += "            <\/div>";
  154. HTML += "        <\/div>";
  155. HTML += "    ";
  156.  
  157. }
  158.  
  159. HTML += "<br><a href=\"http://wish.com/s/7dpgMW\">Mój reflink, odwdzięczcie się ( ?° ?? ?°)</a><\/div>";
  160. HTML += "<script>";
  161. HTML += "$(document).ready(function() {";
  162. HTML += "    $(\"#list\").click(function(event){event.preventDefault();$(\"#products .item\").addClass(\"list-group-item\");});";
  163. HTML += "    $(\"#grid\").click(function(event){event.preventDefault();$(\"#products .item\").removeClass(\"list-group-item\");$(\"#products .item\").addClass(\"grid-group-item\");});";
  164. HTML += "});";
  165. HTML += "<\/script>";
  166. HTML += "<\/body>";
  167. HTML += "<\/html>";
  168.  
  169.                
  170.                
  171. var newWindow = window.open();        
  172.                
  173. newWindow.document.write(HTML);
  174.  
  175. }
  176. function sortByPrice(myArray){
  177. myArray.sort(function(a, b) {
  178.   return a['commerce_product_info']['variations'][0]['price'] - b['commerce_product_info']['variations'][0]['price'];
  179.  
  180.  
  181.         });
  182.  
  183.  
  184. }
  185. function search(text){
  186.  
  187. $.getJSON( "https:\/\/www.wish.com/api/search?start=0&query=" + text + "&price=&transform=true", function( data ) {
  188. //\/\/alert(data);
  189. dupa = data;
  190. ITEMS.push.apply(ITEMS,data['data']['results']);
  191. //alert(ITEMS.length);
  192. var a;
  193. if(dupa['data']['feed_ended']){
  194. if(rabat==true){
  195. filtre(ITEMS);
  196. ItemsWithVariants(ITEMS);
  197. sortByPrice(variantsArray);
  198. showHTML(variantsArray);
  199. a = dupa['data']['num_found']+1;
  200. }
  201. else {variantsArray = ITEMS;
  202.  
  203. sortByPrice(variantsArray);
  204. showHTML(variantsArray);
  205. a = dupa['data']['num_found']+1;
  206. }
  207.  
  208. }
  209.  
  210.  
  211.  
  212. for(a=25; a<= dupa['data']['num_found'] && dupa['data']['feed_ended'] == false; a = a+25){
  213. $.getJSON( "https:\/\/www.wish.com/api/search?start=" + a + "&query=" + text + "&price=&transform=true", function( data ) {
  214. dupa = data;
  215. ITEMS.push.apply(ITEMS,data['data']['results']);
  216. if(dupa['data']['feed_ended']){
  217. if(rabat==true){
  218. filtre(ITEMS);
  219. ItemsWithVariants(ITEMS);
  220. sortByPrice(variantsArray);
  221. showHTML(variantsArray);
  222. a = dupa['data']['num_found']+1;
  223. }
  224. else {
  225. filtre(ITEMS);variantsArray = ITEMS;
  226. sortByPrice(variantsArray);
  227. showHTML(variantsArray);
  228. a = dupa['data']['num_found']+1;
  229. }
  230.  
  231. }
  232. })
  233.  
  234. //alert(ITEMS.length);
  235. }
  236. //\/\/variantsArray = $.makeArray(variantsArray);
  237. }
  238. )}
  239.  
  240.  
  241.  
  242.  
  243. function findPurpose(findID){
  244.     return $.grep(array1, function(item){
  245.       return item.id == findID;
  246.     });
  247. };
  248.  
  249. function lookup(array, prop, value) {
  250.     for (var i = 0, len = array.length; i < len; i++){
  251.         if (array[i][prop] === value){
  252.                         return array[i];
  253.                 }
  254. }
  255.                 }
  256.  
  257. function ItemsWithVariants(array1) {
  258. variantsArray = new Array();
  259. var b = 0;
  260.     for (var i = 0, len = array1.length; i < len; i++){
  261.                 differentPrices = false;
  262.         if (array1[i]['commerce_product_info']['variations'].length > 1){
  263.                         for (var c = 0, len2 = array1[i]['commerce_product_info']['variations'].length; c < len2; c++){
  264.                         if(array1[i]['commerce_product_info']['variations'][c]['price'] != array1[i]['commerce_product_info']['variations'][0]['price']){
  265.                         differentPrices = true;
  266.                         c = array1[i]['commerce_product_info']['variations'].length;
  267.                         }
  268.                         }
  269.                 if(differentPrices == true){
  270.                 variantsArray[b] = array1[i];
  271.                         b++;
  272.                 }
  273.                
  274.                 }
  275.                
  276.                 }
  277.                 return variantsArray;
  278. }
  279. var rabat;
  280. function begin(){
  281.  
  282. a = prompt("Podaj nazwę produktu który chcesz wyszukać");
  283. rabat = confirm("Wyszukać produkty z rabatem?");
  284. minAverage = prompt("Minimalna średnia ocena (jeśli pominąć pozostaw puste)");
  285. minRating = prompt("Minimalna ilość ocen (jeśli pominąć pozostaw puste)");
  286. search(a);
  287. }
  288. begin();
  289. //\/\/ItemsWithVariants(ITEMS);
  290. //\/\/FeedView
  291. /*
  292. function getMinPrice(array){
  293. var price = [];
  294.         for (var c = 0, len = array[i]['commerce_product_info']['variations'].length; c < len; c++){
  295.                         sorted[c]['price'] = array[i]['commerce_product_info']['variations'][c]['price'];
  296.                         sorted[c]['shipprice'] = array[i]['commerce_product_info']['variations'][c]['localized_shipping']['localized_value'];
  297.                         sorted.sort();
  298.                
  299.                        
  300.                        
  301.                         }
  302.                                 console.log(sorted);
  303.                                 return sorted;
  304.                        
  305.                         }
  306.  
  307.  
  308. function getArray(array){
  309.   for (var i = 0, len = array.length; i < len; i++){
  310.                 minprice =
  311.                
  312.                
  313.                 }
  314.  
  315. }
  316.  
  317. */
  318.  
  319.                
  320. //\/\/lookup(array1,"id","53be9319ff4d6d6df1802945");
Advertisement
Add Comment
Please, Sign In to add comment