Skip to content

Instantly share code, notes, and snippets.

@zetavg
Last active May 12, 2020 08:43
Show Gist options
  • Save zetavg/7db9ac904d2f0cc2699fb49a8c51bbaa to your computer and use it in GitHub Desktop.
Save zetavg/7db9ac904d2f0cc2699fb49a8c51bbaa to your computer and use it in GitHub Desktop.
需要注意有些 menu item 是被列在「前一天預定」section 裡,可能要把最後那些挑掉。善用 Paste values only 來貼。
function getGanDanKitMenuItems() {
return Array.from(document.querySelectorAll('.promain'))
.map(e => ({
name: e.querySelector('h3').innerText.replace(/(/g, ' (').replace(/)/g, ')'),
price: parseInt(e.querySelector('em').innerText.replace(/[^0-9]/mg, '')),
}))
// Filter out duplicated items
.filter((v, i, arr) => (arr.findIndex(a => a.name === v.name) === i))
}
function copyGanDanKitMenuItems() {
const items = getGanDanKitMenuItems()
copy(
items
.map(i => `${i.name}\t${i.price}`)
.join('\n')
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment