I am writing an extension. Its logic is as follows: the DOM parsim, we are looking for a price there, we compare it with our given one.
manifest.json
{ "name": "SteamStickergunBuy", "description": "sticker buy", "version": "1.0", "manifest_version": 2, "icons":{ "128":"icons/red.png" }, "browser_action": { "default_title": "ThisIsGooood", "default_icon": "icons/red.png", "default_popup": "popup.html" }, "background": { "scripts": ["background.js"] }, "permissions": [ "http://steamcommunity.com/market/listings/730/*", "tabs", "background" , "storage", "alarms", "notifications" ] } background.html
<div style='display: none' id='example'>Example</div> <script src="background.js"></script> background.js
var items=[ {item_id:"http://steamcommunity.com/market/listings/730/AWP%20%7C%20Asiimov%20%28Battle-Scarred%29",price: '35500'}, {item_id:"http://steamcommunity.com/market/listings/730/AWP%20%7C%20Pit%20Viper%20%28Battle-Scarred%29",price: '35500'}, {item_id:"http://steamcommunity.com/market/listings/730/AWP%20%7C%20Corticera%20%28Field-Tested%29",price: '35500'}, {item_id:"http://steamcommunity.com/market/listings/730/AWP%20%7C%20Corticera%20%28Minimal%20Wear%29",price: '35500'}, {item_id:"http://steamcommunity.com/market/listings/730/AWP%20%7C%20Electric%20Hive%20%28Field-Tested%29",price: '35500'} ]; var i = 0; var timerId = setInterval(function() { var url=items[i].item_id; var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4){ var data = xhr.responseText; document.body.innerHTML=data; var name=document.getElementsByClassName("market_listing_item_name")[0].innerHTML; if(document.getElementsByClassName("market_listing_table_message").length==0){ var market_price = document.getElementsByClassName("market_listing_price market_listing_price_with_fee")[0].innerHTML; var marketPrice = market_price.replace(/[A-Za-zА-Яа-я.]+/, market_price); marketPrice = parseFloat(marketPrice) * 100;//приводим к копейкам if(marketPrice <= items[i].price){ var dannie=document.getElementById("dannie"); dannie.innerHTML=name+":"+marketPrice; } console.log(name+":"+marketPrice); }else{console.log("Не обнаружены лоты для данного предмета с учетом выбранных фильтров.")} } } i++; xhr.send(); }, 10000); And popup.html
<script src="popup.js"></script> <script src="background.js"></script> <div style="height:100px;width:200px;font-size:10px;padding:3px" id="dannie">Ѕлок с данными</div > So the code works. Everything is fine, but the entire page is loaded into popup.html (because I insert xhr.responcetext into the body).
If I insert into the prepared invisible div example (as I want the popup to display only the result), then an error occurs (supposedly equal to zero, it cannot find this div)
How to be? how best to implement it ?. To see if the price is lower than what I asked. In popup.html came out the name of the price and the link is not the subject.