注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
(async function fetchAllFilesDirectUrl() {
const scriptPath = mw.config.get('wgScriptPath') || '';
const apiEndpoint = `${window.location.origin}${scriptPath}/api.php`;
const redirectBaseUrl = `${window.location.origin}${scriptPath}/wiki/Special:%E9%87%8D%E5%AE%9A%E5%90%91/file?wpvalue=`;
let urlList = [];
let apcontinue = '';
console.log('开始获取并生成文件下载链接...');
do {
const params = new URLSearchParams({
action: 'query',
list: 'allpages',
apnamespace: '6', // File 命名空间
aplimit: 'max',
format: 'json',
origin: '*'
});
if (apcontinue) {
params.append('apcontinue', apcontinue);
}
try {
const response = await fetch(`${apiEndpoint}?${params.toString()}`);
const data = await response.json();
if (data.query && data.query.allpages) {
// 直接在获取时拼好完整 Redirect URL
const urls = data.query.allpages.map(page => `${redirectBaseUrl}${encodeURIComponent(page.title)}`);
urlList.push(...urls);
console.log(`已处理 ${urlList.length} 个文件链接...`);
}
apcontinue = data.continue ? data.continue.apcontinue : null;
} catch (error) {
console.error('获取失败:', error);
break;
}
} while (apcontinue);
console.log(`✅ 完成!生成了 ${urlList.length} 个下载链接。`);
// 直接导出拼好的 URL 列表,开箱即用
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 = 'fdm_download_links.txt';
a.click();
URL.revokeObjectURL(url);
})();