// ==UserScript== // @name 微博相册原图批量下载 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 提供微博微相册 ( photo.weibo.com ) 的专辑内单页原图批量下载 // @author ShuangruiYang // @match *://photo.weibo.com/*/talbum/index* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function () { 'use strict'; function batch_download() { let image_list = document.querySelectorAll("ul.photoList li a img"); let number = image_list.length; // 验证预览图是否未加载 是则 等待1秒后再次验证 if (number == 0) { setTimeout(batch_download, 1000); return; } for (let i = 0; i < number; i++) { let id_match = image_list[i].parentNode.href.match(/\d+/g); let album_id = id_match[2]; let photo_id = id_match[1]; // 格式化 原图下载链接 let download_$a = document.createElement('a'); download_$a.id = "download_" + i; download_$a.href = image_list[i].src.replace(/(.+)\/(\w+)\/(\w+)/, "$1/large/$3"); download_$a.download = album_id + "_" + photo_id; fetch(download_$a.href) .then(res => res.blob()) .then(blob => { var blob_url = window.URL.createObjectURL(blob); download_$a.href = blob_url; download_$a.click(); window.URL.revokeObjectURL(blob_url); }); } } function init() { let batch_download_$button = document.createElement("button"); batch_download_$button.id = "batch_download"; batch_download_$button.textContent = "批量下载原图"; batch_download_$button.style.fontWeight = "bolder"; batch_download_$button.onclick = batch_download; document.querySelector(".m_share_like").appendChild(batch_download_$button); } init(); })();