Skip to content

Instantly share code, notes, and snippets.

@grownseed
Last active December 19, 2020 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grownseed/6271713bd448b67a58937b6eadd27b33 to your computer and use it in GitHub Desktop.
Save grownseed/6271713bd448b67a58937b6eadd27b33 to your computer and use it in GitHub Desktop.
const neweggUrl = 'https://www.newegg.ca/p/pl?d=rtx+3070&N=100007708&isdeptsrh=1';
function getInStock() {
$.get({
url: neweggUrl,
dataType: 'html',
success: function(data) {
const timestamp = new Date().toLocaleTimeString();
let inStockHtml = '';
$(data).find('div.item-cell').each(function(i, el) {
const isOutOfStock = /OUT OF STOCK/.test($(this).find('.item-info .item-promo').first().text());
if (!isOutOfStock) {
const link = $(this).find('.item-info a.item-title').first();
const title = link.text();
const href = link.attr('href');
const price = $(this).find('.item-action .price .price-current').first().text();
inStockHtml += `<li><a href="${href}">${price} - ${title}</a></li>`;
}
});
$('#stock-updates').html(`<h3>Last checked: ${timestamp}</h3><ul>${inStockHtml}</ul>`);
}
});
}
$('body').prepend('<div id="stock-updates" style="font-size: 1.2em; padding: 20px; border: solid 4px #ff0000;"></div>');
setInterval(getInStock, 20000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment