Created
December 18, 2021 01:15
-
-
Save alexanderbird/82693d3d6b65b24b085ab350d90abb0b to your computer and use it in GitHub Desktop.
JavaScript to highlight Skip The Dishes receipts for Friday purchases (and add a link for receipt ID to receipt so you can open in new tab)
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
/* let each of the order IDs be links to the receipt */ | |
Array.from(document.querySelectorAll('[class*="OrderData"] [class*="OrderDataText"]:first-child')).forEach(orderSpan => { | |
const orderId = orderSpan.textContent.replace(/^#/, ''); | |
const url = `/user/account/orders/${orderId}/details`; | |
orderSpan.innerHTML = `<a href="${url}">#${orderId}</a>`; | |
}); | |
/* let each of the dates show day of week. Highlight the Fridays */ | |
Array.from(document.querySelectorAll('span')) | |
.filter(span => span.textContent.trim().match(/202[0-9]-\d\d-\d\d/)) | |
.forEach(span => { | |
const dateText = span.textContent.match(/.*(202[0-9]-\d\d-\d\d).*/)[1]; | |
const date = new Date(dateText + 'T12:00:00+0000'); | |
const day = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; | |
span.textContent = day + ', ' + dateText; | |
if (day === 'Fri') { | |
span.style.backgroundColor = '#88FF88'; | |
span.style.color = 'black'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can turn it into a bookmarklet with a tool like https://caiorss.github.io/bookmarklet-maker/. This produces a link which you can drag into your bookmarks bar. Click the link to execute the script.