在页面左下角添加按钮,点击可自动下载所有静态图片
// ==UserScript==
// @name 通用图片下载
// @namespace http://your.namespace/
// @version 0.4
// @description 在页面左下角添加按钮,点击可自动下载所有静态图片
// @author 猛蛮丸
// @run-at document-start
// @match *
// @match *://*/*
// @grant GM_download
// ==/UserScript==
(function() {
'use strict';
function downloadImages(prefix) {
const images = document.querySelectorAll('img');
let count = 1;
images.forEach(image => {
const imgUrl = image.src;
const fileName = prefix + count + '.jpg';
GM_download({
url: imgUrl,
name: fileName,
onload: function() {
console.log('Image downloaded successfully:', imgUrl);
},
onerror: function(error) {
console.error('Error downloading image:', error);
}
});
count++;
});
}
function createDownloadButton() {
const button = document.createElement('button');
button.textContent='🤪';
button.style.position='fixed';
button.style.bottom = '10px';
button.style.left = '10px';
button.style.fontSize = '30px';
button.style.zIndex = '99999';
button.addEventListener('click', function() {
const imageName = prompt('请输入图片名:');
if (imageName) {
downloadImages(imageName);
}
});
document.body.appendChild(button);
}
// 页面加载后创建下载按钮
window.addEventListener('load', createDownloadButton);
})();