Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Rogue Fitness 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);
- };
- // IMPORTANT!
- // This is the list of product IDs that you want to monitor, you get this by using inspect element on a product page.
- // In this case, we are monitoring for the ohio powerlift bar and the matador dip bar
- // Note: You must have the webpages open on your browser where these two products are listed
- // Note: The only thing you need to add below is the product ID, you do not need the comments and the URL that i added (that's just to make it clear to me what the product id is for)
- var productIDs = [
- "60093", // ohio powerlift bar https://www.roguefitness.com/rogue-45lb-ohio-powerlift-bar-cerakote
- "3527", // matador dip bar https://www.roguefitness.com/rogue-infinity-matador
- "85743", // 15 lb fleck = https://www.roguefitness.com/rogue-fleck-plates
- "85745", // 25 lb fleck = https://www.roguefitness.com/rogue-fleck-plates
- "85747", // 35 lb fleck = https://www.roguefitness.com/rogue-fleck-plates
- "85749" // 45 lb fleck = https://www.roguefitness.com/rogue-fleck-plates
- ];
- productIDs.forEach((productID) => {
- var product = document.getElementsByClassName("product-purchase-wrapper-" + productID);
- if(product.length === 0) return;
- console.log("Found product on page: " + productID);
- product = product[0]
- if(product.getElementsByClassName("color-swatch-wrapper").length === 1) {
- // Product has multiple color choices
- var swatch_container = product.getElementsByClassName("color-swatch-container")[0];
- var swatches = swatch_container.querySelectorAll('div[id^="swatch-main-' + productID + '"]');
- for(var swatch_index=0; swatch_index < swatches.length; swatch_index++) {
- var swatch = swatches[swatch_index];
- if(!swatch.classList.contains("swatch-oos")) {
- productNotification();
- break;
- }
- };
- refresh();
- } else if(product.getElementsByClassName("bin-stock-availability").length === 1) {
- console.log("Product not available.");
- refresh();
- } else {
- productNotification();
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement