forked from JessNah/BeeGreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
89 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { analyzeCart } from "./storesCommon" | ||
|
||
export function getAppleCart() { | ||
const _cartItems = document.getElementsByClassName("row rs-iteminfo"); | ||
let cart = []; | ||
for(let i = 0; i < _cartItems.length; i++){ | ||
const priceItem = _cartItems[i].getElementsByClassName("rs-iteminfo-price"); | ||
const textItem = _cartItems[i].getElementsByClassName("rs-iteminfo-title"); | ||
const imageItem = _cartItems[i].getElementsByClassName("as-util-relatedlink")[0].childNodes[0]; | ||
let _item = { | ||
id: textItem[0].childNodes[0].innerText, | ||
name: textItem[0].childNodes[0].innerText, | ||
price: priceItem[0].childNodes[0].childNodes[1].innerText, | ||
image: imageItem | ||
} | ||
cart.push(_item); | ||
} | ||
cart = analyzeCart(cart); | ||
return cart; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getInstaCart } from "./getInstaCart" | ||
import { getAppleCart } from "./getAppleCart" | ||
import { SupportedSites } from "../utils/constants" | ||
|
||
export function getCart(currentStore) { | ||
switch(currentStore){ | ||
case SupportedSites.INSTACART: | ||
return getInstaCart(); | ||
case SupportedSites.APPLESTORE: | ||
return getAppleCart(); | ||
default: | ||
return []; | ||
} | ||
} | ||
|
||
export function analyzeCart(cart) { | ||
for(let item of cart){ | ||
item.score = Math.floor(Math.random() * 10) + 1; | ||
if(item.score > 10){ | ||
item.score = 10; | ||
} | ||
} | ||
cart.sort(compare); | ||
return cart; | ||
} | ||
|
||
export function compare( a, b ) { | ||
if ( a.score < b.score ){ | ||
return 1; | ||
} | ||
if ( a.score > b.score ){ | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
export function getCartAverageRating(cart) { | ||
let score = 0; | ||
for(let item of cart){ | ||
score += item.score; | ||
} | ||
if(cart.length <= 0 ){ | ||
return 0; | ||
} | ||
return score/cart.length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters