Skip to content

Commit

Permalink
Add price and tweak for wishlist page
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyestein committed Dec 31, 2023
1 parent 029dbb6 commit a076cb7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ For https://www.flaticon.com/free-icon/wine_4698198?term=wine&related_id=4698198

<a href="https://www.flaticon.com/free-icons/wine" title="wine icons">Wine icons created by iconixar - Flaticon</a>


# TODO

Make it work on past order page too.

Layout of basket summary text is weird.

Better styling.

Make initialisation less hacky.

36 changes: 30 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ function dataItemFromBI(bi) {
var stock_status_span = bi.querySelector('.badge-label');
var item_code = bi.querySelector('.basket-item__code');


try {
// these might not exist if item is out of stock
var quantity_value_sel = bi.querySelector('.basket-item__quantity-select select');
var quantity_value = quantity_value_sel.value;
var quantity_unit_sel = bi.querySelector('.basket-item__type select');
var quantity_unit = quantity_unit_sel.selectedOptions[0].innerText; // only one can be selected
var price = bi.querySelector('.basket-item__price').innerText;
} catch (err) {
var quantity_value = '?';
var quantity_unit = '?';
var quantity_value = '';
var quantity_unit = '';
var price = '';
}
var item = {
wine: wine_desc,
code: item_code.innerText,
url: abs_url,
stock: stock_status_span.innerText,
price: price,
qty_val: quantity_value,
qty_unit: quantity_unit
};
Expand All @@ -32,6 +36,21 @@ function getAllBasketItems() {
return document.querySelectorAll('li.basket-item');
}

function determinePage() {
if(/www.thewinesociety.com\/wishlist/.test(window.location.href)) {
return "wishlist";
} else if(/www.thewinesociety.com\/basket/.test(window.location.href)) {
return "basket";
} else if(/www.thewinesociety.com\/my-account\/order-history\/order-details/.test(window.location.href)) {
return "order";
} else {
return null;
}
}

/**
* Generate and update the string at the top saying how many bottles/cases are in the basket
*/
function updateSummaryString() {
var summaryDiv = document.querySelector('.summary-text-jes');
if (summaryDiv === null) {
Expand All @@ -55,7 +74,7 @@ function updateSummaryString() {
}

function formatItemAsStr(item) {
return `| ${item.wine} | ${item.code} | ${item.url} | ${item.stock} | ${item.qty_val} | ${item.qty_unit} |`;
return `| ${item.wine} | ${item.code} | ${item.url} | ${item.stock} | ${item.price} | ${item.qty_val} | ${item.qty_unit} |`;
}

function makeCopyButtons() {
Expand All @@ -80,8 +99,11 @@ function makeCopyButtons() {
var all_butt = document.createElement('BUTTON');
all_butt.className = copy_all_button_class;
all_butt.onclick = () => {
let copyStr = '| wine | code | url | stock | qty_val | qty_unit |\n'
+ '| --- | --- | --- | --- | --- | --- |\n';
let page = determinePage();
let timestamp = new Date().toLocaleString();
let copyStr = `Copied from ${page} at ${timestamp}:\n\n` // double LF or table doesn't render in obsidian
+ '| wine | code | url | stock | price | qty_val | qty_unit |\n'
+ '| --- | --- | --- | --- | --- | --- | --- |\n';
for (let bi of getAllBasketItems()) {
var item = dataItemFromBI(bi);
copyStr += formatItemAsStr(item) + '\n';
Expand Down Expand Up @@ -134,5 +156,7 @@ function makeCopyButtons() {

var fruitless_run_count = 0;
var intervalID = setInterval(makeCopyButtons, 1000);
setInterval(updateSummaryString, 1000);
if (determinePage() == 'basket') {
setInterval(updateSummaryString, 1000);
}

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version":2,
"version":"1.0",
"name":"Wine Society link extractor",
"description": "Extracts tabular data from shopping basket, wishlist, etc",
"name":"Wine Society basket summariser",
"description": "Displays summary and extracts tabular data from shopping basket, wishlist, etc",

"permissions": [
"activeTab"
Expand Down

0 comments on commit a076cb7

Please sign in to comment.