1document.addEventListener("DOMContentLoaded", ApiProducts); 2 3 function ApiProducts(){ 4 var tables = document.querySelectorAll('table.tovari'); 5 if(tables){ 6 var products_id = []; 7 var price_elms = {}; 8 for(var i = 0; i <tables.length;i++){ 9 var table_products = tables[i].querySelectorAll('tr')[0]; 10 if(table_products){ 11 table_products = table_products.querySelectorAll('td'); 12 if(table_products){ 13 for(var t=1;t<table_products.length;t++){ 14 if(table_products[t].querySelector('img').hasAttribute("data-productid")){ 15 if(typeof price_elms[i] == 'undefined'){ 16 price_elms[i] = {}; 17 } 18 products_id[products_id.length] = table_products[t].querySelector('img').getAttribute('data-productid'); 19 price_elms[i][table_products[t].querySelector('img').getAttribute('data-productid')] = t; 20 } 21 } 22 } 23 } 24 } 25 if(products_id.length){ 26 var xhr = new XMLHttpRequest(); 27 xhr.open('GET', '/wp-admin/admin-ajax.php?action=load_products&products_id='+products_id.join(','), true); 28 xhr.responseType = 'json'; 29 xhr.send(); 30 xhr.onreadystatechange = function() { 31 if (xhr.readyState != 4) return; 32 33 if (xhr.status == 200) { 34 // обÑабоÑаÑÑ Ð¾ÑÐ¸Ð±ÐºÑ 35 36 var response = xhr.response; 37 if(!response.error){ 38 for(var index in price_elms) { 39 var table_index = index; 40 for(var ind in price_elms[index]){ 41 var index_search = price_elms[index][ind]; 42 var product_id = ind; 43 if(response.content.hasOwnProperty(product_id)){ 44 if(response.content[product_id].hasOwnProperty('price')){ 45 var table_price_add = tables[table_index].querySelectorAll('tr'); 46 if(table_price_add){ 47 table_price_add[table_price_add.length-2].querySelectorAll('td')[index_search].innerHTML = 'Ð¾Ñ '+response.content[product_id].price; 48 } 49 } 50 if(response.content[product_id].hasOwnProperty('url') && response.content[product_id].url != ''){ 51 var table_url = tables[table_index].querySelectorAll('tr'); 52 if(table_url){ 53 table_url[table_url.length-1].querySelectorAll('td')[index_search].querySelector('a').href = response.content[product_id].url; 54 } 55 } 56 } 57 } 58 } 59 } 60 } 61 62 } 63 } 64 65 } 66 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.