注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
(async function fetchAllDirectImageUrls() {
const scriptPath = mw.config.get('wgScriptPath') || '';
const apiEndpoint = `${window.location.origin}${scriptPath}/api.php`;
let urlList = [];
let aicontinue = '';
console.log('开始获取图片直链...');
do {
const params = new URLSearchParams({
action: 'query',
list: 'allimages', // 直接查图片表
ailimit: 'max',
format: 'json',
origin: '*'
});
if (aicontinue) {
params.append('aicontinue', aicontinue);
}
try {
const response = await fetch(`${apiEndpoint}?${params.toString()}`);
const data = await response.json();
if (data.query && data.query.allimages) {
// 直接读取图片的原图 URL (url 字段)
const urls = data.query.allimages.map(img => img.url);
urlList.push(...urls);
console.log(`已获取 ${urlList.length} 个原图直链...`);
}
aicontinue = data.continue ? data.continue.aicontinue : null;
} catch (error) {
console.error('获取失败:', error);
break;
}
} while (aicontinue);
console.log(`✅ 获取完成!共找到 ${urlList.length} 个原图直链。`);
const blob = new Blob([urlList.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'direct_image_urls.txt';
a.click();
URL.revokeObjectURL(url);
})();