Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Last active September 10, 2022 21:01
Show Gist options
  • Save s-hiiragi/4a2014ed957ca4cfb87daf8d530387ae to your computer and use it in GitHub Desktop.
Save s-hiiragi/4a2014ed957ca4cfb87daf8d530387ae to your computer and use it in GitHub Desktop.
Amazonの注文履歴を取得するブックマークレット
javascript:(()=>{
const orders = Array.from(document.querySelectorAll('#ordersContainer > .order'));
let records = orders.flatMap(order => {
const id = order.querySelector('.yohtmlc-order-id .value').textContent.trim();
const date = order.querySelector('.a-span3 .value').textContent.trim();
const total = order.querySelector('.yohtmlc-order-total .value').textContent.trim();
const itemTitles = Array.from(
order.querySelectorAll('.yohtmlc-item > .a-row:nth-child(1)')).
map(e => e.textContent.trim());
return { id: id, date: date, total: total, titles: itemTitles.join('、') };
});
records.forEach(e => {
const m = /(\d{4})年(\d{1,2})月(\d{1,2})/.exec(e.date);
e.date = [m[1], m[2], m[3]].join('/');
e.total = e.total.replace(/^¥ /, '').replace(/,/g, '');
});
const s = records.map(e => [e.id, e.date, e.total, e.titles].join('\t')).join('\n');
console.log(s);
prompt('orders', s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment