Last active
January 28, 2024 03:48
-
-
Save catboxanon/fa297d9a104b7dc63f92b444cbe51b39 to your computer and use it in GitHub Desktop.
Save DALL-3 images on current page with Ctrl+S
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
// ==UserScript== | |
// @name DALL-3 Save | |
// @namespace bingdall3save | |
// @match https://www.bing.com/images/create* | |
// @version 1.0.2 | |
// @author Anonymous | |
// @updateURL https://gist.github.com/raw/fa297d9a104b7dc63f92b444cbe51b39/dall-3-save.user.js | |
// @downloadURL https://gist.github.com/raw/fa297d9a104b7dc63f92b444cbe51b39/dall-3-save.user.js | |
// @require https://cdn.jsdelivr.net/npm/file-saver | |
// ==/UserScript== | |
(async function() { | |
async function fetchBlob(url) { | |
try { | |
const response = await fetch(url); | |
if (response.ok) { | |
return response.blob(); | |
} | |
} catch (err) { | |
return; | |
} | |
} | |
window.addEventListener('keydown', async (evt) => { | |
if (!(evt.ctrlKey && evt.key === 's')) { | |
return; | |
} | |
evt.preventDefault(); | |
const imgEls = document.querySelector('div[data-vimgseturl]')?.querySelectorAll('img[alt]:not([src$=".svg"])'); | |
for await (const imgEl of imgEls) { | |
const altText = imgEl.alt.split('. Image')?.[0]; | |
const bingId = `OIG${imgEl.src.split('id/OIG')?.[1]?.split('?w')?.[0]}`; | |
const filename = `${altText} - ${bingId}.jpg`; | |
const imgFullRes = imgEl.src.split('?w')?.[0]; | |
if (filename && imgFullRes) { | |
const imgBlob = await fetchBlob(imgFullRes); | |
saveAs(imgBlob, filename); | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment