Skip to content

Instantly share code, notes, and snippets.

@denikus
Created August 29, 2018 12:45
Show Gist options
  • Save denikus/fdee5d328faef4a6a85acee9ca75951d to your computer and use it in GitHub Desktop.
Save denikus/fdee5d328faef4a6a85acee9ca75951d to your computer and use it in GitHub Desktop.
function pageFunction(context) {
var $ = context.jQuery; // get query context
var priceElem = $(".shopee-product-info__header__real-price"); // main selector what we are waiting for, mounting
function delay(selector, callback, count) { // delay function
if (selector.length && count !== 0) { // if selector is on page and count isnt zero move to get data callback
return callback(); // get data callback
} else if (count === 0) { // if count zero, we are already wait 20*6000 ms do context.skipOutput();
context.skipOutput(); // i dont know what is that
} else { // if not previous action then wait 6s and try agin until count === 0 (20 times)
setTimeout(function () { delay(selector, callback, count - 1); }, 6000);
}
}
function getData() { // this func get text data from fields and return it;
var regPriceField = $(".shopee-product-info__header__price-before-discount__number"),
priceField = $(".shopee-product-info__header__real-price"),
sockField = $(".shopee-product-info-body__order-quantity__stock-count"),
regPrice, price, stock;
if (regPriceField && regPriceField.length > 0) {
regPrice = regPriceField.text();
} else {
regPrice = 'no data';
}
if (priceField && priceField.length > 0) {
price = priceField.text();
} else {
price = 'no data';
}
if (sockField && sockField.length > 0) {
stock = sockField.text().trim();
} else {
stock = 'no data';
}
return {
regPrice,
price,
stock
}
}
var result = delay(priceElem, getData, 20); // start to cicle func
return result; // return result from "pageFunction" do with it all waht you want
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment