|
|
@@ -0,0 +1,102 @@
|
|
|
+class DownloadTool {
|
|
|
+ constructor() {
|
|
|
+ this.form = document.getElementById('downloadForm');
|
|
|
+ this.output = document.getElementById('output');
|
|
|
+ this.loadUrlsBtn = document.getElementById('loadUrls');
|
|
|
+ this.urlListTextarea = document.getElementById('urlList');
|
|
|
+ this.downloadUrlBtn = document.getElementById('downloadUrl');
|
|
|
+ this.downloadImageBtn = document.getElementById('downloadImage');
|
|
|
+ this.clearOutputBtn = document.getElementById('clearOutput');
|
|
|
+
|
|
|
+ this.initEvents();
|
|
|
+ }
|
|
|
+
|
|
|
+ initEvents() {
|
|
|
+ // 读取URL按钮
|
|
|
+ this.loadUrlsBtn.addEventListener('click', () => {
|
|
|
+ this.loadTargetUrls();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 下载URL按钮
|
|
|
+ this.downloadUrlBtn.addEventListener('click', () => {
|
|
|
+ this.showOutput('下载URL被点击', 'success');
|
|
|
+ });
|
|
|
+
|
|
|
+ // 下载图片按钮
|
|
|
+ this.downloadImageBtn.addEventListener('click', () => {
|
|
|
+ this.showOutput('下载IMG被点击', 'success');
|
|
|
+ });
|
|
|
+
|
|
|
+ // 清除输出按钮
|
|
|
+ this.clearOutputBtn.addEventListener('click', () => {
|
|
|
+ this.clearOutput();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async loadTargetUrls() {
|
|
|
+ try {
|
|
|
+ this.showOutput('正在读取 targets.txt...', '');
|
|
|
+
|
|
|
+ const response = await fetch('/load_urls', {
|
|
|
+ method: 'POST'
|
|
|
+ });
|
|
|
+
|
|
|
+ const result = await response.json();
|
|
|
+
|
|
|
+ if (result.success) {
|
|
|
+ // 在URL列表文本框中显示读取的URL
|
|
|
+ this.urlListTextarea.value = result.urls.join('\n');
|
|
|
+ this.showOutput(`成功读取 ${result.urls.length} 个URL`, 'success');
|
|
|
+ } else {
|
|
|
+ this.showOutput(`读取失败: ${result.message}`, 'error');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.showOutput(`读取URL时出错: ${error.message}`, 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async clearOutput() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/clear', {
|
|
|
+ method: 'POST'
|
|
|
+ });
|
|
|
+
|
|
|
+ const result = await response.json();
|
|
|
+ if (result.success) {
|
|
|
+ this.showOutput('', 'success');
|
|
|
+ this.urlListTextarea.value = ''; // 同时清空URL列表
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.showOutput(`清除失败: ${error.message}`, 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ showOutput(message, type = '') {
|
|
|
+ this.output.textContent = message;
|
|
|
+ this.output.className = 'output-area';
|
|
|
+ if (type) {
|
|
|
+ this.output.classList.add(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动滚动到底部
|
|
|
+ this.output.scrollTop = this.output.scrollHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ setLoading(loading) {
|
|
|
+ const buttons = this.form.querySelectorAll('button');
|
|
|
+ buttons.forEach(button => {
|
|
|
+ button.disabled = loading;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (loading) {
|
|
|
+ document.body.classList.add('loading');
|
|
|
+ } else {
|
|
|
+ document.body.classList.remove('loading');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 初始化应用
|
|
|
+document.addEventListener('DOMContentLoaded', () => {
|
|
|
+ new DownloadTool();
|
|
|
+});
|