SHARE
TWEET

REP Fitness Stock Notifier

dhillonsh May 28th, 2020 1,906 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Rep Fitness Stock Notifier
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Notifier for Rep Fitness Stock
  6. // @author       dhillonsh
  7. // @match        https://www.repfitness.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     var browserAlert = function () {
  15.         var oldTitle = document.title;
  16.         var msg = "New!";
  17.         var timeoutId;
  18.         var blink = function() { document.title = document.title == msg ? ' ' : msg; };
  19.         var clear = function() {
  20.             clearInterval(timeoutId);
  21.             document.title = oldTitle;
  22.             window.onmousemove = null;
  23.             timeoutId = null;
  24.         };
  25.         return function () {
  26.             if (!timeoutId) {
  27.                 timeoutId = setInterval(blink, 1000);
  28.                 window.onmousemove = clear;
  29.             }
  30.         };
  31.     };
  32.  
  33.     var productNotification = function () {
  34.         console.log("Product available.");
  35.         browserAlert();
  36.  
  37.         var player = document.createElement('audio');
  38.         player.src = 'https://notificationsounds.com/soundfiles/a86c450b76fb8c371afead6410d55534/file-sounds-1108-slow-spring-board.mp3';
  39.         player.preload = 'auto';
  40.         player.play()
  41.  
  42.         var xhttp = new XMLHttpRequest();
  43.         xhttp.open("GET", "http://localhost:8080/?title=" + document.title, true);
  44.         xhttp.send();
  45.     };
  46.  
  47.     var refresh = function() {
  48.         var seconds = 30;
  49.         setTimeout(function() {
  50.             var params = new URLSearchParams(window.location.search);
  51.             var new_url = window.location.href.split('?')[0];
  52.             if(params.get("iteration") === null) {
  53.                 new_url = new_url + "?iteration=1";
  54.             } else {
  55.                 new_url = new_url + "?iteration=" + (parseInt(params.get("iteration")) + 1);
  56.             }
  57.             window.location.replace(new_url);
  58.         }, seconds * 1000);
  59.     };
  60.  
  61.     var productIDs = [
  62.         "2316" // AB-5200 Adjustable Bench https://www.repfitness.com/ab-5200-bench
  63.     ];
  64.  
  65.     productIDs.forEach((productID) => {
  66.         console.log(document.querySelectorAll('[data-product-id="' + productID + '"]'));
  67.         if(document.querySelectorAll('[data-product-id="' + productID + '"]').length === 0) return;
  68.  
  69.         console.log("Found product on page: " + productID);
  70.  
  71.         if(document.getElementsByClassName("out-of-stock").length > 0) {
  72.            console.log("Product not available.");
  73.  
  74.            refresh();
  75.        } else {
  76.             productNotification();
  77.        }
  78.     });
  79.  
  80. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top