Skip to content

Instantly share code, notes, and snippets.

@adamthedeveloper
Last active August 21, 2020 20:09
Show Gist options
  • Save adamthedeveloper/2928be55949dac5197fdb7a4946e1d29 to your computer and use it in GitHub Desktop.
Save adamthedeveloper/2928be55949dac5197fdb7a4946e1d29 to your computer and use it in GitHub Desktop.
Tamper monkey script for transferring ASI Product data to Brilliant Catalog.
// ==UserScript==
// @name Create product in brilliant
// @namespace http://espweb.asicentral.com
// @version 0.3
// @description Adds a button to ASI's esp detail pages which takes users back to the brilliant site allowing them to create the product there.
// @author Adam Medeiros
// @match *://espweb.asicentral.com/Default.aspx*page=ProductDetails*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
var brilliantServerDomain = "https://www.brilliantbranded.com";
var asiUrl = encodeURIComponent(window.location.href);
var queryString = decodeURIComponent(window.location.search.substring(1));
var variables = queryString.split('&');
var varMap = {};
for (var i=0; i<variables.length; i++) {
var pair = variables[i].split('=');
varMap[pair[0].toLowerCase()] = pair[1];
}
var productId = varMap.productid;
$('body').append("<div style='position: fixed; bottom: 0; left: 0; height: 50px; background-color: #cccccc; width: 100%; padding: 10px; z-index: 1000;'><div style='width:25%; float: left;'><img style='width: 40%;' src='" + brilliantServerDomain + "/images/logo.svg' /></div><div style='width: 25%; float: left; margin-top: 6px;'>ASI ID: " + productId + "&nbsp;<a href='" + brilliantServerDomain + "/admin/products/new?asiProductID=" + productId + "&asiUrl=" + asiUrl + "' target='_blank'>Add this product to the BRILLIANT catalog</a></div><div id='product_check' style='width: 25%; float: left; margin-top: 6px;'></div></div>");
$.ajax({
url: brilliantServerDomain + "/api/asi_product_exists/" + productId + ".js",
dataType: "jsonp",
success: function(data) {
if (data) {
$('div#product_check').css('color','red').html("WARNING!! Product already exists. Find it <a href='" + brilliantServerDomain + "/admin/products/" + data.id + "' target='_blank'>here</a>.");
} else {
$('div#product_check').css('color','green').html("Good to go! This product has not been saved.");
}
},
error: function() {
console.log(arguments);
},
timeout: 5000
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment