Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //by R4v.pl, 2014 for Wykop.pl
- //\/\/https:\/\/www.wish.com/api/search?start=0&query=test&price=&transform=true
- var dupa;
- var ITEMS = [];
- var ITEMSsorted = [];
- function setMinAverage(array1, value) {
- var b = 0;
- for (var i = 0, len = array1.length; i < len; i++){
- moreThan = false;
- if(array1[i]['product_rating']['rating'] >= value && array1[i]['product_rating']['rating_count'] > 0)
- moreThan = true;
- if(moreThan == true){
- ITEMS[b] = array1[i];
- b++;
- }
- }
- return ITEMS;
- }
- function setMinRating(array1, value) {
- var b = 0;
- for (var i = 0, len = array1.length; i < len; i++){
- moreThan = false;
- if(array1[i]['product_rating']['rating_count'] >= value)
- moreThan = true;
- if(moreThan == true){
- ITEMS[b] = array1[i];
- b++;
- }
- }
- return ITEMS;
- }
- function filtre(ITEMS){
- if (minAverage !=0) setMinAverage(ITEMS, minAverage);
- if (minRating !=0) setMinRating(ITEMS, minRating);
- }
- function showHTML(array){
- var HTML ="";
- HTML += "<html><head> <link href=\"\/\/netdna.bootstrapcdn.com\/bootstrap\/3.1.1\/css\/bootstrap.min.css\" rel=\"stylesheet\">";
- HTML += "<\/head><body> <script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.0\/jquery.min.js\"><\/script>";
- HTML += " <script src=\"\/\/netdna.bootstrapcdn.com\/bootstrap\/3.1.1\/js\/bootstrap.min.js\"><\/script><style>";
- HTML += ".glyphicon { margin-right:5px; }";
- HTML += ".thumbnail";
- HTML += "{";
- HTML += " margin-bottom: 20px;";
- HTML += " padding: 0px;";
- HTML += " -webkit-border-radius: 0px;";
- HTML += " -moz-border-radius: 0px;";
- HTML += " border-radius: 0px;";
- HTML += "}";
- HTML += "";
- HTML += ".item.list-group-item";
- HTML += "{";
- HTML += " float: none;";
- HTML += " width: 100%;";
- HTML += " background-color: #fff;";
- HTML += " margin-bottom: 10px;";
- HTML += "}";
- HTML += ".item.list-group-item:nth-of-type(odd):hover,.item.list-group-item:hover";
- HTML += "{";
- HTML += " background: #428bca;";
- HTML += "}";
- HTML += "";
- HTML += ".item.list-group-item .list-group-image";
- HTML += "{";
- HTML += " margin-right: 10px;";
- HTML += "}";
- HTML += ".item.list-group-item .thumbnail";
- HTML += "{";
- HTML += " margin-bottom: 0px;";
- HTML += "}";
- HTML += ".item.list-group-item .caption";
- HTML += "{";
- HTML += " padding: 9px 9px 0px 9px;";
- HTML += "}";
- HTML += ".item.list-group-item:nth-of-type(odd)";
- HTML += "{";
- HTML += " background: #eeeeee;";
- HTML += "}";
- HTML += "";
- HTML += ".item.list-group-item:before, .item.list-group-item:after";
- HTML += "{";
- HTML += " display: table;";
- HTML += " content: \" \";";
- HTML += "}";
- HTML += "";
- HTML += ".item.list-group-item img";
- HTML += "{";
- HTML += " float: left;";
- HTML += "}";
- HTML += ".item.list-group-item:after";
- HTML += "{";
- HTML += " clear: both;";
- HTML += "}";
- HTML += ".list-group-item-text";
- HTML += "{";
- HTML += " margin: 0 0 11px;";
- HTML += "}";
- HTML += "";
- HTML += "<\/style>";
- HTML += "<div class=\"container\">";
- HTML += " <div class=\"well well-sm\">";
- HTML += " <strong>Wyniki<\/strong>";
- HTML += " <div class=\"btn-group\">";
- HTML += " <a href=\"#\" id=\"list\" class=\"btn btn-default btn-sm\"><span class=\"glyphicon glyphicon-th-list\">";
- HTML += " <\/span>Lista<\/a> <a href=\"#\" id=\"grid\" class=\"btn btn-default btn-sm\"><span";
- HTML += " class=\"glyphicon glyphicon-th\"><\/span>Grid<\/a>";
- HTML += " <\/div>";
- HTML += " <\/div>";
- HTML += " <div id=\"products\" class=\"row list-group\">";
- for (var i = 0, len = array.length; i < len; i++){
- var TITLE = array[i]['name'];
- var IMG =array[i]['small_picture'];
- /*if (typeof array[i]['description'] === 'undefined') {
- var DESCRIPTION = array[i]['name'];
- }
- else */ var DESCRIPTION = array[i]['name'];
- var PRICE =array[i]['commerce_product_info']['variations'][0]['price'] + " + " + array[i]['commerce_product_info']['variations'][0]['shipping'] + " " + array[i]['localized_value']['symbol'];
- var URL =array[i]['external_url'];
- HTML += "<div class=\"item col-xs-4 col-lg-4\">";
- HTML += " <div class=\"thumbnail\">";
- HTML += " <img class=\"group list-group-image\" src=" + IMG + " alt=\"\" \/>";
- HTML += " <div class=\"caption\">";
- HTML += " <h4 class=\"group inner list-group-item-heading\">";
- HTML += " "+ TITLE + "<\/h4>";
- HTML += " <p class=\"group inner list-group-item-text\">";
- HTML += " " + DESCRIPTION + "<\/p>";
- HTML += " <div class=\"row\">";
- HTML += " <div class=\"col-xs-12 col-md-6\">";
- HTML += " <p class=\"lead\">";
- HTML += " " + PRICE + "<\/p>";
- HTML += " <\/div>";
- HTML += " <div class=\"col-xs-12 col-md-6\">";
- HTML += " <a class=\"btn btn-success\" target=\"_blank\" href=" + URL + ">Przejdź<\/a>";
- HTML += " <\/div>";
- HTML += " <\/div>";
- HTML += " <\/div>";
- HTML += " <\/div>";
- HTML += " <\/div>";
- HTML += " ";
- }
- HTML += "<br><a href=\"http://wish.com/s/7dpgMW\">Mój reflink, odwdzięczcie się ( ?° ?? ?°)</a><\/div>";
- HTML += "<script>";
- HTML += "$(document).ready(function() {";
- HTML += " $(\"#list\").click(function(event){event.preventDefault();$(\"#products .item\").addClass(\"list-group-item\");});";
- HTML += " $(\"#grid\").click(function(event){event.preventDefault();$(\"#products .item\").removeClass(\"list-group-item\");$(\"#products .item\").addClass(\"grid-group-item\");});";
- HTML += "});";
- HTML += "<\/script>";
- HTML += "<\/body>";
- HTML += "<\/html>";
- var newWindow = window.open();
- newWindow.document.write(HTML);
- }
- function sortByPrice(myArray){
- myArray.sort(function(a, b) {
- return a['commerce_product_info']['variations'][0]['price'] - b['commerce_product_info']['variations'][0]['price'];
- });
- }
- function search(text){
- $.getJSON( "https:\/\/www.wish.com/api/search?start=0&query=" + text + "&price=&transform=true", function( data ) {
- //\/\/alert(data);
- dupa = data;
- ITEMS.push.apply(ITEMS,data['data']['results']);
- //alert(ITEMS.length);
- var a;
- if(dupa['data']['feed_ended']){
- if(rabat==true){
- filtre(ITEMS);
- ItemsWithVariants(ITEMS);
- sortByPrice(variantsArray);
- showHTML(variantsArray);
- a = dupa['data']['num_found']+1;
- }
- else {variantsArray = ITEMS;
- sortByPrice(variantsArray);
- showHTML(variantsArray);
- a = dupa['data']['num_found']+1;
- }
- }
- for(a=25; a<= dupa['data']['num_found'] && dupa['data']['feed_ended'] == false; a = a+25){
- $.getJSON( "https:\/\/www.wish.com/api/search?start=" + a + "&query=" + text + "&price=&transform=true", function( data ) {
- dupa = data;
- ITEMS.push.apply(ITEMS,data['data']['results']);
- if(dupa['data']['feed_ended']){
- if(rabat==true){
- filtre(ITEMS);
- ItemsWithVariants(ITEMS);
- sortByPrice(variantsArray);
- showHTML(variantsArray);
- a = dupa['data']['num_found']+1;
- }
- else {
- filtre(ITEMS);variantsArray = ITEMS;
- sortByPrice(variantsArray);
- showHTML(variantsArray);
- a = dupa['data']['num_found']+1;
- }
- }
- })
- //alert(ITEMS.length);
- }
- //\/\/variantsArray = $.makeArray(variantsArray);
- }
- )}
- function findPurpose(findID){
- return $.grep(array1, function(item){
- return item.id == findID;
- });
- };
- function lookup(array, prop, value) {
- for (var i = 0, len = array.length; i < len; i++){
- if (array[i][prop] === value){
- return array[i];
- }
- }
- }
- function ItemsWithVariants(array1) {
- variantsArray = new Array();
- var b = 0;
- for (var i = 0, len = array1.length; i < len; i++){
- differentPrices = false;
- if (array1[i]['commerce_product_info']['variations'].length > 1){
- for (var c = 0, len2 = array1[i]['commerce_product_info']['variations'].length; c < len2; c++){
- if(array1[i]['commerce_product_info']['variations'][c]['price'] != array1[i]['commerce_product_info']['variations'][0]['price']){
- differentPrices = true;
- c = array1[i]['commerce_product_info']['variations'].length;
- }
- }
- if(differentPrices == true){
- variantsArray[b] = array1[i];
- b++;
- }
- }
- }
- return variantsArray;
- }
- var rabat;
- function begin(){
- a = prompt("Podaj nazwę produktu który chcesz wyszukać");
- rabat = confirm("Wyszukać produkty z rabatem?");
- minAverage = prompt("Minimalna średnia ocena (jeśli pominąć pozostaw puste)");
- minRating = prompt("Minimalna ilość ocen (jeśli pominąć pozostaw puste)");
- search(a);
- }
- begin();
- //\/\/ItemsWithVariants(ITEMS);
- //\/\/FeedView
- /*
- function getMinPrice(array){
- var price = [];
- for (var c = 0, len = array[i]['commerce_product_info']['variations'].length; c < len; c++){
- sorted[c]['price'] = array[i]['commerce_product_info']['variations'][c]['price'];
- sorted[c]['shipprice'] = array[i]['commerce_product_info']['variations'][c]['localized_shipping']['localized_value'];
- sorted.sort();
- }
- console.log(sorted);
- return sorted;
- }
- function getArray(array){
- for (var i = 0, len = array.length; i < len; i++){
- minprice =
- }
- }
- */
- //\/\/lookup(array1,"id","53be9319ff4d6d6df1802945");
Advertisement
Add Comment
Please, Sign In to add comment