Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- // Check every x seconds
- var CHECK_FREQUENCY = 60;
- var regex = /<div class="pricetable">(.*)<\/div>/g,
- beep = document.createElement("audio"),
- current = getText(document.getElementsByClassName("pricetable")[0].innerHTML);
- // Initialize beep
- beep.id = "beep";
- beep.autoplay = false;
- beep.src = "https://www.soundjay.com/button/beep-07.mp3";
- document.body.appendChild(beep);
- function scrape() {
- console.log("Scraping...");
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- var next = getText(this.responseText.match(regex)); // Next deal?
- if (next != current) {
- current = next;
- notify();
- } else {
- setTimeout(scrape, CHECK_FREQUENCY * 1000);
- }
- }
- };
- xhr.open("GET", "/black-friday-cyber-monday/?" + Date.now(), true);
- xhr.send();
- }
- // Strip HTML tags
- function getText(html) {
- var div = document.createElement("div");
- div.innerHTML = html;
- return div.textContent || div.innerText || "";
- }
- // Notify you
- function notify() {
- var i = 0;
- setTimeout(function() {
- alert("NEW DEAL!\n\n" + current + "\n\n" + "Press OK to reload");
- location.reload();
- }, 800);
- setInterval(function() {
- i++;
- if (i > 3) return;
- beep.pause();
- beep.currentTime = 0;
- beep.play();
- }, 200);
- }
- scrape();
- })();
Advertisement
Add Comment
Please, Sign In to add comment