Skip to content

Instantly share code, notes, and snippets.

@mlb5000
Last active August 29, 2015 14:05
Show Gist options
  • Save mlb5000/3823a7773f42569d708e to your computer and use it in GitHub Desktop.
Save mlb5000/3823a7773f42569d708e to your computer and use it in GitHub Desktop.
TF Fitting Room User Script
// ==UserScript==
// @name Tailored Fit Fitting Rooms
// @namespace https://local.tailoredfit.com
// @version 0.8
// @description Schedule a fitting room to be prepared at your favorite stores!
// @match https://*.blueandcream.com
// @match http://*.blueandcream.com
// @match https://www.blueandcream.com
// @match http://www.blueandcream.com
// @match https://www.blueandcream.com/*
// @match http://www.blueandcream.com/*
// @match http://*.kisanstore.com/*
// @match https://*.kisanstore.com/*
// @match http://*.montmartreny.com/*
// @match https://*.montmartreny.com/*
// @match http://*.christopherfischer.com/*
// @match https://*.christopherfischer.com/*
// @match http://*.life-curated.com/*
// @match https://*.life-curated.com/*
// @match http://*.frenchgarmentcleaners.com/*
// @match https://*.frenchgarmentcleaners.com/*
// @match http://*.bylangley.com/*
// @match https://*.bylangley.com/*
// @match http://*.openingceremony.us/*
// @match https://*.openingceremony.us/*
// @match http://*.mnzstore.com/*
// @match https://*.mnzstore.com/*
// @match http://assemblynewyork.com/*
// @match https://assemblynewyork.com/*
// @copyright 2012+, You
// ==/UserScript==
(function() {
function fittingRooms() {
this.injectButton();
}
fittingRooms.prototype = {
injectButton: function() {
(function(d, script) {
var style = d.createElement('link');
style.type = 'text/css';
style.async = true;
style.rel = 'stylesheet';
style.href = 'https://local.tailoredfit.com/v1/api.css';
style.onload = function () {
script = d.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
var path = '/retailerByHostname';
var data = {
hostname: location.host
};
var success = function(xhr) {
var result = JSON.parse(xhr.responseText);
var retailer = result.retailer;
/*jslint evil: true */
var title = eval(retailer.titlejavascript);
var img_url = eval(retailer.imageurljavascript);
/*jslint evil: false */
if (!title || !img_url) {
return;
}
var buttonText = 'Book a Fitting Room!';
if (TailoredFit.Res.getSessionId()) {
buttonText = 'Add to Fitting Room!';
}
var type = retailer.appendbuttonto.split(':')[0];
var selector = retailer.appendbuttonto.split(':')[1];
var elem;
if (type === "id") {
elem = document.getElementById(selector);
} else {
var elems = document.getElementsByClassName(selector);
if (elems.length === 0) {
return;
}
elem = elems[0];
}
if (!elem) {
return;
}
var button = d.createElement('input');
button.type = 'button';
button.value = buttonText;
button.id = 'tf-button';
elem.appendChild(button);
TailoredFit.Res.init(retailer.id, 'tf-button', {
url: location.href,
sku_id: '',
product_name: title,
image_url: img_url
});
};
var failure = function(xhr) {
};
TailoredFit.Res.base_url = "https://local.tailoredfit.com";
TailoredFit.Res.getData(path, data, success, failure);
};
script.src = 'https://local.tailoredfit.com/v1/api.js';
d.getElementsByTagName('head')[0].appendChild(script);
};
var font = document.createElement('link');
//<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
font.href='https://fonts.googleapis.com/css?family=Open+Sans:400,600';
font.rel='stylesheet';
font.type='text/css';
font.onload = function() {
d.getElementsByTagName('head')[0].appendChild(style);
};
d.getElementsByTagName('head')[0].appendChild(font);
}(document));
}
};
var tffitting = new fittingRooms();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment