Last active
December 19, 2020 00:50
-
-
Save grownseed/6271713bd448b67a58937b6eadd27b33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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