Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Rogue Fitnes Alternative Stock Notifier
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Notifier for Rogue Fitness Stock
- // @author dhillonsh
- // @match https://www.roguefitness.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- var browserAlert = function () {
- var oldTitle = document.title;
- var msg = "New!";
- var timeoutId;
- var blink = function() { document.title = document.title == msg ? ' ' : msg; };
- var clear = function() {
- clearInterval(timeoutId);
- document.title = oldTitle;
- window.onmousemove = null;
- timeoutId = null;
- };
- return function () {
- if (!timeoutId) {
- timeoutId = setInterval(blink, 1000);
- window.onmousemove = clear;
- }
- };
- };
- var productNotification = function () {
- console.log("Product available.");
- browserAlert();
- var player = document.createElement('audio');
- player.src = 'https://notificationsounds.com/soundfiles/a86c450b76fb8c371afead6410d55534/file-sounds-1108-slow-spring-board.mp3';
- player.preload = 'auto';
- player.play()
- var xhttp = new XMLHttpRequest();
- xhttp.open("GET", "http://localhost:8080/?title=" + document.title, true);
- xhttp.send();
- };
- var refresh = function() {
- var seconds = 30;
- setTimeout(function() {
- var params = new URLSearchParams(window.location.search);
- var new_url = window.location.href.split('?')[0];
- if(params.get("iteration") === null) {
- new_url = new_url + "?iteration=1";
- } else {
- new_url = new_url + "?iteration=" + (parseInt(params.get("iteration")) + 1);
- }
- window.location.replace(new_url);
- }, seconds * 1000);
- };
- var productIDs = {
- // Product ID
- "87425": { // Monster Utility Bench 2.0
- // Discriminator for an attribute
- "4326": { // Bench Height
- // Discriminator for the value within the option
- "6127": [ // Shorty Height
- // Discriminator for additional options
- "6129", // Standard Pad
- "6131", // Competition Pad
- "6133" // Thompson Fat Pad
- ]
- }
- }
- };
- for(var productID in productIDs) {
- var product = document.getElementsByClassName("product-purchase-wrapper-" + productID);
- if(product.length === 0) return;
- console.log("Found product on page: " + productID);
- product = product[0];
- var productAttributes = window["spConfig" + productID].config.attributes
- // Iterate over the attributes we care about
- for(var attribute in productIDs[productID]) {
- var desiredOptions = productIDs[productID][attribute];
- // Iterate over all possible options for this attribute
- productAttributes[attribute].options.forEach((option) => {
- // If this is an option we're actually monitoring
- if(Object.keys(desiredOptions).includes(option.id)) {
- console.log("Found specific combination on page: ProductID=" + productID + " | Attribute=" + attribute + " | Option=" + option.id);
- // Iterate over the additional options we care about
- productIDs[productID][attribute][option.id].forEach((additional_option) => {
- console.log("Found specific combination on page: ProductID=" + productID + " | Attribute=" + attribute + " | Option=" + option.id + " | AdditionalOption=" + additional_option);
- if(option.additional_options[option.id + "," + additional_option].isInStock === true) {
- productNotification();
- }
- });
- }
- });
- }
- console.log("Product not available.");
- refresh();
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement