123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>邮件删除工具</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- max-width: 800px;
- margin: 20px auto;
- padding: 20px;
- }
- .container {
- border: 1px solid #ccc;
- padding: 20px;
- border-radius: 5px;
- }
- .form-group {
- margin-bottom: 15px;
- }
- label {
- display: block;
- margin-bottom: 5px;
- }
- input[type="datetime-local"] {
- padding: 5px;
- width: 250px;
- }
- input[type="text"],
- input[type="password"] {
- padding: 5px;
- width: 250px;
- margin-bottom: 10px;
- border: 1px solid #ccc;
- border-radius: 4px;
- }
- button {
- background-color: #4CAF50;
- color: white;
- padding: 10px 20px;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- button:hover {
- background-color: #45a049;
- }
- #logArea {
- margin-top: 20px;
- padding: 10px;
- border: 1px solid #ddd;
- border-radius: 4px;
- height: 300px;
- overflow-y: auto;
- background-color: #f9f9f9;
- }
- .log-entry {
- margin: 5px 0;
- padding: 5px;
- border-bottom: 1px solid #eee;
- }
- .pagination-info {
- margin: 10px 0;
- padding: 5px;
- background-color: #f0f0f0;
- border-radius: 4px;
- font-size: 14px;
- color: #666;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h2>邮件删除工具</h2>
- <div class="form-group">
- <label for="email">邮箱账号:</label>
- <input type="text" id="email" required value="spdrakuten@spdsystem.com">
- </div>
- <div class="form-group">
- <label for="password">邮箱密码:</label>
- <input type="password" id="password" required value="YzFiMTJlYT2a4-4a">
- </div>
- <div class="form-group">
- <label for="startPage">起始页码:</label>
- <input type="number" id="startPage" required min="1" value="100">
- </div>
- <div class="form-group">
- <label for="endPage">结束页码:</label>
- <input type="number" id="endPage" min="1" placeholder="留空则删除到最后一页">
- </div>
- <div class="pagination-info" id="paginationInfo"></div>
- <button onclick="startDelete()">开始删除</button>
- <button onclick="testConnection()" style="background-color: #2196F3;">测试连接</button>
- <div id="logArea"></div>
- </div>
- <script>
- function addLog(message) {
- const logArea = document.getElementById('logArea');
- const logEntry = document.createElement('div');
- logEntry.className = 'log-entry';
- logEntry.textContent = `${new Date().toLocaleTimeString()} - ${message}`;
- logArea.insertBefore(logEntry, logArea.firstChild);
- }
-
- async function startDelete() {
- const email = document.getElementById('email').value;
- const password = document.getElementById('password').value;
- const startPage = parseInt(document.getElementById('startPage').value);
- const endPage = document.getElementById('endPage').value ? parseInt(document.getElementById('endPage').value) : null;
-
- if (!email || !password) {
- alert('请输入邮箱账号和密码');
- return;
- }
-
- if (!startPage || startPage < 1) {
- alert('请输入有效的起始页码');
- return;
- }
-
- if (endPage !== null && endPage < startPage) {
- alert('结束页码必须大于或等于起始页码');
- return;
- }
-
- console.log('Selected page range:', { startPage, endPage });
- addLog('开始删除邮件...');
-
- try {
- const response = await fetch('/start-delete', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- email,
- password,
- startPage,
- endPage
- })
- });
-
- const result = await response.json();
-
- if (!response.ok) {
- throw new Error(result.message || '删除请求失败');
- }
-
- addLog('删除请求已发送,开始监听进度...');
-
- // Close any existing EventSource
- if (window.eventSource) {
- window.eventSource.close();
- }
-
- // Create new EventSource
- window.eventSource = new EventSource('/delete-progress');
- addLog('正在建立事件流连接...');
-
- window.eventSource.onopen = () => {
- addLog('与服务器的连接已建立');
- };
-
- window.eventSource.onmessage = (event) => {
- try {
- const data = JSON.parse(event.data);
- addLog(data.message);
- if (data.paginationInfo) {
- document.getElementById('paginationInfo').textContent = data.paginationInfo;
- }
-
- // Check if deletion is complete
- if (data.message.includes('删除完成')) {
- window.eventSource.close();
- addLog('删除操作完成,连接已关闭');
- }
- } catch (error) {
- console.error('Error parsing message:', error);
- addLog('收到未格式化消息: ' + event.data); // 如果解析失败,直接显示原始消息
- }
- };
-
- window.eventSource.onerror = (error) => {
- addLog('连接错误,尝试重新连接...');
- console.error('EventSource error:', error);
-
- // Close the connection on error and try to reconnect
- if (window.eventSource) {
- window.eventSource.close();
-
- // Try to reconnect after a short delay
- setTimeout(() => {
- addLog('尝试重新连接...');
- window.eventSource = new EventSource('/delete-progress');
- }, 3000);
- }
- };
- } catch (error) {
- addLog(`错误: ${error.message}`);
- }
- }
-
- async function testConnection() {
- addLog('测试连接中...');
-
- // Create test event source
- if (window.testEventSource) {
- window.testEventSource.close();
- }
-
- window.testEventSource = new EventSource('/delete-progress');
-
- window.testEventSource.onopen = () => {
- addLog('测试连接成功!');
- };
-
- window.testEventSource.onmessage = (event) => {
- addLog('收到消息: ' + event.data);
- };
-
- window.testEventSource.onerror = (error) => {
- addLog('测试连接失败');
- console.error('Test connection error:', error);
- window.testEventSource.close();
- };
-
- // Also call the test endpoint
- try {
- const response = await fetch('/test-event');
- const data = await response.json();
- addLog('服务器响应: ' + JSON.stringify(data));
- } catch (error) {
- addLog('请求测试端点失败: ' + error.message);
- }
- }
- </script>
- </body>
- </html>
|