
@@ -149,6 +157,41 @@
})
}
+ function csvEscape(value) {
+ const str = String(value ?? '')
+ if (/[",\r\n]/.test(str)) {
+ return '"' + str.replace(/"/g, '""') + '"'
+ }
+ return str
+ }
+
+ function exportWatchlistCsv() {
+ const rows = Array.from(document.querySelectorAll('.watchlist-item')).map(function(item) {
+ return [
+ item.dataset.malId || '',
+ item.dataset.title || item.querySelector('h3')?.textContent.trim() || '',
+ item.dataset.status || '',
+ ]
+ })
+
+ const csv = [
+ ['mal_id', 'title', 'status'],
+ ...rows,
+ ].map(function(row) {
+ return row.map(csvEscape).join(',')
+ }).join('\r\n')
+
+ const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' })
+ const url = URL.createObjectURL(blob)
+ const link = document.createElement('a')
+ link.href = url
+ link.download = 'watchlist.csv'
+ document.body.appendChild(link)
+ link.click()
+ link.remove()
+ URL.revokeObjectURL(url)
+ }
+
// Ensure items are sorted correctly on initial load
window.addEventListener('DOMContentLoaded', () => {
sortItems()