Skip to content

Commit 9695b0c

Browse files
committed
Condensed download routines ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/amazongpt]
1 parent 0349465 commit 9695b0c

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

chatgpt/amazongpt/amazongpt.user.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @description Add AI chat & product/category summaries to Amazon shopping, powered by the latest LLMs like GPT-4o!
44
// @author KudoAI
55
// @namespace https://kudoai.com
6-
// @version 2025.12.16
6+
// @version 2026.1.3
77
// @license MIT
88
// @icon https://amazongpt.kudoai.com/assets/images/icons/app/black-gold-teal/icon48.png?v=8e8ed1c
99
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/app/black-gold-teal/icon64.png?v=8e8ed1c
@@ -911,17 +911,12 @@
911911

912912
// Download code
913913
const code = codeBlock.textContent.replace(/^>> /, '').trim() + '\n'
914-
const dlLink = dom.create.anchor(URL.createObjectURL(new Blob([code], { type: 'text/plain' })))
915-
const now = new Date(), formattedDate = [ // YYYY-MM-DD
916-
now.getFullYear(),
917-
String(now.getMonth() +1).padStart(2, '0'),
918-
String(now.getDate()).padStart(2, '0')
919-
].join('-')
920-
dlLink.download /* filename */ = `${app.slug}_${blockLang.name.toLowerCase() || 'code'}_${
921-
formattedDate}_${Date.now().toString(36)}${
922-
blockLang.fileExtension ? '.' + blockLang.fileExtension : '' }`
923-
document.body.append(dlLink) ; dlLink.click() ; dlLink.remove() // download code
924-
URL.revokeObjectURL(dlLink.href) // prevent memory leaks
914+
const date = new Date().toISOString().split('T')[0] // YYYY-MM-DD
915+
const download = `${app.slug}_${blockLang.name.toLowerCase() || 'code'}_${
916+
date}_${Date.now().toString(36)}${blockLang.fileExtension ? '.' + blockLang.fileExtension : ''}`
917+
const href = URL.createObjectURL(new Blob([code], { type: 'text/plain' }))
918+
const a = dom.create.anchor(href, '', { download, style: 'display: none' })
919+
document.body.append(a) ; a.click() ; a.remove() ; URL.revokeObjectURL(href)
925920
}
926921
downloadBtn.onmouseenter = downloadBtn.onmouseleave = tooltip.toggle
927922

@@ -1875,15 +1870,14 @@
18751870
xhr({
18761871
method: 'GET', url: shareURL,
18771872
onload: ({ responseText }) => {
1878-
const dlLink = dom.create.anchor(
1879-
URL.createObjectURL(new Blob([responseText], { type: 'text/html' })))
1880-
dlLink.download /* filename */ = responseText.match(/<title>([^<]+)<\/title>/i)[1]
1873+
const download = responseText.match(/<title>([^<]+)<\/title>/i)[1]
18811874
.replace(/\s*[|/]+\s*/g, ' ') // convert symbols to space for hyphen-casing
18821875
.replace(/\.{2,}/g, '') // strip ellipsis
18831876
.toLowerCase().trim().replace(/\s+/g, '-') // hyphen-case
18841877
+ '.html'
1885-
document.body.append(dlLink) ; dlLink.click() ; dlLink.remove() // download HTML
1886-
URL.revokeObjectURL(dlLink.href) // prevent memory leaks
1878+
const href = URL.createObjectURL(new Blob([responseText], { type: 'text/html' }))
1879+
const a = dom.create.anchor(href, '', { download, style: 'display: none' })
1880+
document.body.append(a) ; a.click() ; a.remove() ; URL.revokeObjectURL(href)
18871881
},
18881882
onerror: err => log.error('Failed to download chat:', err)
18891883
})

0 commit comments

Comments
 (0)