Skip to content

Commit

Permalink
Added Adidas.com
Browse files Browse the repository at this point in the history
  • Loading branch information
mrboomer committed Mar 9, 2016
1 parent 721df6a commit 8eca9e5
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 7 deletions.
70 changes: 66 additions & 4 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/*globals $, chrome, window, setInterval, footlocker */

function loadSettings(callback) {
chrome.storage.local.get(['yasbActive', 'sizeSelected', 'shoeSize', 'checkout'], function(response) {
chrome.storage.local.get(['yasbActive', 'sizeSelected', 'shoeSize', 'cart', 'checkout'], function(response) {
callback(response);
});
}
Expand Down Expand Up @@ -57,12 +57,13 @@ function runYasb(response) {
if (response.yasbActive && response.sizeSelected) {
$(function(){
var shoeSize = response.shoeSize,
continueCart = response.cart,
continueCheckout = response.checkout;

// FinishLine.com
var finishlinecom = setInterval(function() {

if(window.location.href.indexOf("product") > -1) {
if(window.location.href.indexOf('finishline') > -1 && window.location.href.indexOf('product') > -1) {
var $cartWindow = $('#ui-dialog-title-addToCartModal'),
strippedShoeSize = shoeSize.replace(/^(0+)/g, ''),
$itemSize = $('#productSizes.isShoe .size:contains("' + strippedShoeSize + '")');
Expand All @@ -71,8 +72,8 @@ function runYasb(response) {
// Stop Function Call
clearInterval(finishlinecom);

// Continue to Checkout if Selected in Settings
if (continueCheckout) {
// Continue to Cart/Shopping Cart if Selected in Settings
if (continueCart || continueCheckout) {
window.location.href = "/store/checkout/cart.jsp";
}

Expand All @@ -97,13 +98,74 @@ function runYasb(response) {
}
}
}
else if (window.location.href.indexOf('finishline') > -1 && window.location.href.indexOf('checkout/cart') > -1) {
// Stop Function Call
clearInterval(finishlinecom);

// Continue to Checkout if Selected in Settings
if (continueCheckout) {
$('[name="Checkout"]').click();
}

return;
}
else {
// End if not on Product Page
clearInterval(finishlinecom);
return;
}
}, 250);

// Adidas.com
var adidascom = setInterval(function() {

if(window.location.href.indexOf('adidas') > -1 && $('form[name="addProductForm"]').length) {
var $cartWindow = $('.dialog_minicartoverlay'),
strippedShoeSize = shoeSize.replace(/^0+/,'').replace(/\.?0*$/,''),
$itemSize = $('form[name="addProductForm"] .ffSelectMenuMid > ul > li span:contains("' + strippedShoeSize + '"):first');

if($cartWindow.length) {
// Stop Function Call
clearInterval(adidascom);

// Continue to Cart if Selected in Settings
if (continueCart) {
window.location.href = "/on/demandware.store/Sites-adidas-US-Site/en_US/Cart-Show";
}

// Continue to Checkout if Selected in Settings
if (continueCheckout) {
window.location.href = "https://www.adidas.com/us/checkout-start";
}

return;
}
else {
if ($itemSize.length && !$itemSize.hasClass('unavailable')) {
// Size Avaibale - Select Shoe Size
$itemSize.click();

// Add Shoe to Cart
$('[name="add-to-cart-button"]').click();
}
else {
// Size Unavaibale - Stop YASB
clearInterval(adidascom);

// Notify User
yasbAlert('size-unavailable');

return;
}
}
}
else {
// End if not on Product Page
clearInterval(adidascom);
return;
}
}, 250);

});
}
}
Expand Down
22 changes: 22 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/*global $, chrome, Materialize */

var $shoeSizeInput = $('#shoe-size'),
$cartInput = $('#to-cart'),
$checkoutInput = $('#to-checkout'),
$saveSettings = $('#save');

Expand All @@ -50,11 +51,20 @@ function loadState(response) {

function saveState(response) {
var shoeSize = $shoeSizeInput.val(),
cart = $cartInput.val(),
checkout = $checkoutInput.val();
if (shoeSize) {
chrome.storage.local.set({'shoeSize': shoeSize, 'sizeSelected': true});
if (response.yasbActive) { chrome.runtime.sendMessage({badgeColor: '#66bb6a'}); }
}

if ($cartInput.is(':checked')) {
chrome.storage.local.set({'cart': true});
}
else {
chrome.storage.local.set({'cart': false});
}

if ($checkoutInput.is(':checked')) {
chrome.storage.local.set({'checkout': true});
}
Expand All @@ -63,6 +73,18 @@ function saveState(response) {
}
}

$cartInput.change(function() {
if (this.checked) {
$checkoutInput.prop('checked', false);
}
});

$checkoutInput.change(function() {
if (this.checked) {
$cartInput.prop('checked', false);
}
});

// Save Settings
$saveSettings.click(function() {
getState(saveState);
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
"manifest_version": 2,
"name": "Yet Another Shoe Bot",
"version": "0.4.1",
"version": "0.5.0",
"description": "Automatically add shoes on a page to your shopping cart as soon as the site allows you to buy the shoes.",
"icons": {
"64": "img/yasb-64.png",
Expand All @@ -43,13 +43,13 @@
},
"content_scripts": [
{
"matches": ["*://www.finishline.com/*"],
"matches": ["*://www.finishline.com/*", "*://www.adidas.com/*"],
"css": ["css/vendor/remodal.css","css/vendor/remodal-default-theme.css","css/content.css"],
"js": ["js/vendor/jquery-2.2.1.min.js","js/vendor/remodal.min.js","js/content.js"]
}
],
"web_accessible_resources": ["img/yasb-64.png"],
"minimum_chrome_version": "48",
"options_page": "options.html",
"permissions": ["storage","*://www.finishline.com/*"]
"permissions": ["storage","*://www.finishline.com/*","*://www.adidas.com/*"]
}
6 changes: 6 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ <h5 class="header col s12 offset-m1 m10 offset-l2 l8 light description"></h5>
<label>Shoe Size</label>
</div>
</div>
<div class="row">
<div class="col s12 offset-m2 m8 offset-l3 l6">
<input type="checkbox" id="to-cart" />
<label for="to-cart">Proceed to website's <strong>Cart</strong> after shoe is added to cart.</label>
</div>
</div>
<div class="row">
<div class="col s12 offset-m2 m8 offset-l3 l6">
<input type="checkbox" id="to-checkout" />
Expand Down

0 comments on commit 8eca9e5

Please sign in to comment.