feat: reuse tabs across multi-run — no more tab bloat

- tabRegistry preserved across resetState (like seenCodes/accounts)
- New reuseOrCreateTab() helper: navigates existing tab or creates new one
- All steps use reuseOrCreateTab: VPS panel, auth page, mail
- Mail tabs: only activate if alive, don't re-navigate (preserves session)
- Auth tab: reused between step 2→6→8, navigated to new URLs
- VPS tab: reused across runs, re-injected on navigation
This commit is contained in:
unknown
2026-04-05 10:49:40 +08:00
parent 69b5b780f8
commit 1286130023
7 changed files with 265 additions and 110 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ async function step6_loginChatGPT() {
// Get state for email and password
const state = await chrome.runtime.sendMessage({ type: 'GET_STATE' });
const email = state.email;
const password = state.password || 'mimashisha0.0';
const password = state.password;
if (!email) throw new Error('No email found in state. Complete earlier steps first.');
+37 -25
View File
@@ -184,37 +184,49 @@ async function deleteEmail(item, step) {
try {
log(`Step ${step}: Deleting email...`);
// Right-click on the mail item to trigger context menu
const rect = item.getBoundingClientRect();
item.dispatchEvent(new MouseEvent('contextmenu', {
bubbles: true, cancelable: true, button: 2,
clientX: rect.left + rect.width / 2,
clientY: rect.top + rect.height / 2,
}));
// Strategy 1: Click the trash icon inside the mail item
// Each mail item has: <b class="nui-ico nui-ico-delete" title="删除邮件" sign="trash">
// These icons appear on hover, so we trigger mouseover first
item.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
item.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
await sleep(300);
// Wait for context menu to appear
let deleteMenuItem = null;
for (let i = 0; i < 10; i++) {
const trashIcon = item.querySelector('[sign="trash"], .nui-ico-delete, [title="删除邮件"]');
if (trashIcon) {
trashIcon.click();
log(`Step ${step}: Clicked trash icon`, 'ok');
await sleep(1500);
// Check if item disappeared (confirm deletion)
const stillExists = document.getElementById(item.id);
if (!stillExists || stillExists.style.display === 'none') {
log(`Step ${step}: Email deleted successfully`);
} else {
log(`Step ${step}: Email may not have been deleted, item still visible`, 'warn');
}
return;
}
// Strategy 2: Select checkbox then click toolbar delete button
log(`Step ${step}: Trash icon not found, trying checkbox + toolbar delete...`);
const checkbox = item.querySelector('[sign="checkbox"], .nui-chk');
if (checkbox) {
checkbox.click();
await sleep(300);
const menuItems = document.querySelectorAll('.nui-menu-item .nui-menu-item-text');
for (const mi of menuItems) {
if (mi.textContent.trim() === '删除邮件') {
deleteMenuItem = mi.closest('.nui-menu-item');
break;
// Click toolbar delete button
const toolbarBtns = document.querySelectorAll('.nui-btn .nui-btn-text');
for (const btn of toolbarBtns) {
if (btn.textContent.replace(/\s/g, '').includes('删除')) {
btn.closest('.nui-btn').click();
log(`Step ${step}: Clicked toolbar delete`, 'ok');
await sleep(1500);
return;
}
}
if (deleteMenuItem) break;
}
if (deleteMenuItem) {
deleteMenuItem.click();
log(`Step ${step}: Clicked "删除邮件"`, 'ok');
// Wait for the delete to process and item to disappear
await sleep(1000);
log(`Step ${step}: Email deleted successfully`);
} else {
log(`Step ${step}: Context menu "删除邮件" not found`, 'warn');
}
log(`Step ${step}: Could not delete email (no delete button found)`, 'warn');
} catch (err) {
log(`Step ${step}: Failed to delete email: ${err.message}`, 'warn');
}
+16 -3
View File
@@ -111,7 +111,8 @@ async function step3_fillEmailPassword(payload) {
}
}
fillInput(passwordInput, payload.password || 'mimashisha0.0');
if (!payload.password) throw new Error('No password provided. Step 3 requires a generated password.');
fillInput(passwordInput, payload.password);
log('Step 3: Password filled');
// Report complete BEFORE submit, because submit causes page navigation
@@ -265,8 +266,20 @@ async function step8_clickContinue() {
}
log('Step 8: Found "继续" button, clicking...');
simulateClick(continueBtn);
log('Step 8: Clicked "继续", redirecting to localhost... (background will capture URL)');
// Use native .click() — simulateClick (dispatchEvent) may not trigger form submit
continueBtn.click();
log('Step 8: Clicked via .click()');
// Also try submitting the form directly as a fallback
await sleep(500);
const form = continueBtn.closest('form');
if (form) {
form.requestSubmit(continueBtn);
log('Step 8: Also triggered form.requestSubmit()');
}
log('Step 8: Redirecting to localhost... (background will capture URL)');
// Don't reportComplete — background handles it via webNavigation listener
}