FAT32_

VirMach BF

Nov 25th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     // Check every x seconds
  3.     var CHECK_FREQUENCY = 60;
  4.  
  5.     var regex   = /<div class="pricetable">(.*)<\/div>/g,
  6.         beep    = document.createElement("audio"),
  7.         current = getText(document.getElementsByClassName("pricetable")[0].innerHTML);
  8.  
  9.     // Initialize beep
  10.     beep.id       = "beep";
  11.     beep.autoplay = false;
  12.     beep.src      = "https://www.soundjay.com/button/beep-07.mp3";
  13.     document.body.appendChild(beep);
  14.  
  15.     function scrape() {
  16.         console.log("Scraping...");
  17.         var xhr = new XMLHttpRequest();
  18.         xhr.onreadystatechange = function() {
  19.             if (this.readyState == 4 && this.status == 200) {
  20.                 var next = getText(this.responseText.match(regex)); // Next deal?
  21.                 if (next != current) {
  22.                     current = next;
  23.                     notify();
  24.                 } else {
  25.                     setTimeout(scrape, CHECK_FREQUENCY * 1000);
  26.                 }
  27.             }
  28.         };
  29.         xhr.open("GET", "/black-friday-cyber-monday/?" + Date.now(), true);
  30.         xhr.send();
  31.     }
  32.  
  33.     // Strip HTML tags
  34.     function getText(html) {
  35.         var div = document.createElement("div");
  36.         div.innerHTML = html;
  37.         return div.textContent || div.innerText || "";
  38.     }
  39.  
  40.     // Notify you
  41.     function notify() {
  42.         var i = 0;
  43.  
  44.         setTimeout(function() {
  45.             alert("NEW DEAL!\n\n" + current + "\n\n" + "Press OK to reload");
  46.             location.reload();
  47.         }, 800);
  48.  
  49.         setInterval(function() {
  50.             i++;
  51.             if (i > 3) return;
  52.             beep.pause();
  53.             beep.currentTime = 0;
  54.             beep.play();
  55.         }, 200);
  56.     }
  57.  
  58.     scrape();
  59. })();
Advertisement
Add Comment
Please, Sign In to add comment