SHARE
TWEET

Rogue Fitness Alternative Stock Notifier

dhillonsh Jun 6th, 2020 4,176 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Rogue Fitnes Alternative Stock Notifier
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Notifier for Rogue Fitness Stock
  6. // @author       dhillonsh
  7. // @match        https://www.roguefitness.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.         // Product ID
  63.         "87425": { // Monster Utility Bench 2.0
  64.  
  65.             // Discriminator for an attribute
  66.             "4326": { // Bench Height
  67.  
  68.                 // Discriminator for the value within the option
  69.                 "6127": [ // Shorty Height
  70.  
  71.                     // Discriminator for additional options
  72.                     "6129", // Standard Pad
  73.                     "6131", // Competition Pad
  74.                     "6133" // Thompson Fat Pad
  75.                 ]
  76.             }
  77.         }
  78.     };
  79.  
  80.     for(var productID in productIDs) {
  81.         var product = document.getElementsByClassName("product-purchase-wrapper-" + productID);
  82.  
  83.         if(product.length === 0) return;
  84.  
  85.         console.log("Found product on page: " + productID);
  86.  
  87.         product = product[0];
  88.  
  89.         var productAttributes = window["spConfig" + productID].config.attributes
  90.         // Iterate over the attributes we care about
  91.         for(var attribute in productIDs[productID]) {
  92.             var desiredOptions = productIDs[productID][attribute];
  93.  
  94.             // Iterate over all possible options for this attribute
  95.             productAttributes[attribute].options.forEach((option) => {
  96.              // If this is an option we're actually monitoring
  97.                 if(Object.keys(desiredOptions).includes(option.id)) {
  98.                     console.log("Found specific combination on page: ProductID=" + productID + " | Attribute=" + attribute + " | Option=" + option.id);
  99.  
  100.                     // Iterate over the additional options we care about
  101.                     productIDs[productID][attribute][option.id].forEach((additional_option) => {
  102.                         console.log("Found specific combination on page: ProductID=" + productID + " | Attribute=" + attribute + " | Option=" + option.id + " | AdditionalOption=" + additional_option);
  103.                         if(option.additional_options[option.id + "," + additional_option].isInStock === true) {
  104.                             productNotification();
  105.                         }
  106.                     });
  107.                 }
  108.             });
  109.         }
  110.  
  111.        console.log("Product not available.");
  112.        refresh();
  113.     };
  114.  
  115. })();
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