This bookmarklet downloads up to four images from a Twitter page, and names them based on the username, tweet ID, and image number. It only works on Twitter pages and will throw an error if run on a different website.
javascript:(async()=>{if(location.hostname.match(/\.?twitter\.com$/)){let[,t,,e]=location.pathname.split("/");return[...document.getElementsByTagName("img")].filter(t=>t.src.startsWith("https://pbs.twimg.com/media/")).slice(0,4).map((a,c)=>({url:a.src.replace(/&name=.+/,""),name:`Title-twitter-${t}-${e}-${c+1}.jpg`}))}throw Error("This page is not supported.")})().then(t=>t.forEach(async({url:t,name:e})=>{let a=document.createElement("a");a.href=URL.createObjectURL(await (await fetch(t,{mode:"cors"})).blob()),a.download=e,a.click()})).catch(t=>alert(t))
- Twitter (filename:
Title-twitter-{username}-{tweet_id}-{photo_index}.jpg
)
(async () => {
if (location.hostname.match(/\.?twitter\.com$/)) {
// Twitter
const [, username, , tweetId] = location.pathname.split("/");
return [...document.getElementsByTagName("img")]
.filter((img) => img.src.startsWith("https://pbs.twimg.com/media/"))
.slice(0, 4)
.map((img, i) => ({
url: img.src.replace(/&name=.+/, ""),
name: `Title-twitter-${username}-${tweetId}-${i + 1}.jpg`,
}));
}
throw new Error("This page is not supported.");
})()
.then((images) => images.forEach(async ({ url, name }) => {
const a = document.createElement("a");
a.href = URL.createObjectURL(await (await fetch(url, { mode: "cors" })).blob());
a.download = name;
a.click();
}))
.catch((error) => alert(error));
Pixiv に対応させようとしたら、どうやら Pixiv は画像の表示の仕組みが複雑っぽくて、うまくダウンロードできなかった。