Skip to content

Instantly share code, notes, and snippets.

@catboxanon
Last active January 28, 2024 03:48
Show Gist options
  • Save catboxanon/fa297d9a104b7dc63f92b444cbe51b39 to your computer and use it in GitHub Desktop.
Save catboxanon/fa297d9a104b7dc63f92b444cbe51b39 to your computer and use it in GitHub Desktop.
Save DALL-3 images on current page with Ctrl+S
// ==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