dp-worker 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.d.ts +6 -13
- package/dist/agent/agent.js +9 -19
- package/dist/agent/agent.js.map +1 -1
- package/dist/browser/chrome-process.d.ts +3 -0
- package/dist/browser/chrome-process.js +101 -13
- package/dist/browser/chrome-process.js.map +1 -1
- package/dist/browser/manager.d.ts +4 -4
- package/dist/browser/manager.js +94 -44
- package/dist/browser/manager.js.map +1 -1
- package/dist/center/session-sync.d.ts +16 -77
- package/dist/center/session-sync.js +58 -303
- package/dist/center/session-sync.js.map +1 -1
- package/dist/chrome-extension/omni-flow/background.js +561 -0
- package/dist/chrome-extension/omni-flow/content.js +29 -0
- package/dist/chrome-extension/omni-flow/icon.png +0 -0
- package/dist/chrome-extension/omni-flow/inject.js +173 -0
- package/dist/chrome-extension/omni-flow/manifest.json +44 -0
- package/dist/chrome-extension/omni-flow/popup.css +819 -0
- package/dist/chrome-extension/omni-flow/popup.html +284 -0
- package/dist/chrome-extension/omni-flow/popup.js +1021 -0
- package/dist/chrome-extension/omni-flow/usage_guide.md +139 -0
- package/dist/index.js +15 -45
- package/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/domain.d.ts +4 -4
- package/node_modules/dp-shared/dist/domain.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/domain.js +4 -4
- package/node_modules/dp-shared/dist/domain.js.map +1 -1
- package/node_modules/dp-shared/dist/identities.d.ts +22 -0
- package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/identities.js +3 -0
- package/node_modules/dp-shared/dist/identities.js.map +1 -1
- package/node_modules/dp-shared/dist/index.d.ts +1 -0
- package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/index.js +1 -0
- package/node_modules/dp-shared/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts +85 -0
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js +59 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js.map +1 -0
- package/node_modules/dp-shared/dist/rest-contracts.d.ts +12 -1
- package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/rest-contracts.js +5 -3
- package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.d.ts +4 -4
- package/node_modules/dp-shared/src/admin-broadcast.ts +38 -0
- package/node_modules/dp-shared/src/audit-contracts.ts +33 -0
- package/node_modules/dp-shared/src/configs-contracts.ts +206 -0
- package/node_modules/dp-shared/src/db-rows.ts +280 -0
- package/node_modules/dp-shared/src/deploy-contracts.ts +38 -0
- package/node_modules/dp-shared/src/domain.ts +124 -0
- package/node_modules/dp-shared/src/identities.ts +36 -0
- package/node_modules/dp-shared/src/index.ts +25 -0
- package/node_modules/dp-shared/src/omni-flow-session.ts +80 -0
- package/node_modules/dp-shared/src/rest-contracts.ts +409 -0
- package/node_modules/dp-shared/src/task-history-contracts.ts +115 -0
- package/node_modules/dp-shared/src/worker-detail-contracts.ts +230 -0
- package/node_modules/dp-shared/src/ws-protocol.ts +435 -0
- package/package.json +2 -4
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OmniFlow - Popup UI Controller
|
|
3
|
+
* Manages form state, handles timezone API detection, and synchronizes configuration to local storage.
|
|
4
|
+
* ENFORCED SAFE MODE: Always runs in Proxy Mode. Uses IP Leak Lock if proxy is unconfigured.
|
|
5
|
+
* UX UPGRADES: Standalone Window Mode, Infinite Draft Auto-Save, Real-time Diagnostic (ping0.cc style), and Profile Migration Cloner (Cookies + Settings).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// DOM Elements
|
|
9
|
+
const themeToggleBtn = document.getElementById('themeToggle');
|
|
10
|
+
const openWindowBtn = document.getElementById('openWindowBtn');
|
|
11
|
+
const closeWindowBtn = document.getElementById('closeWindowBtn');
|
|
12
|
+
|
|
13
|
+
// Smart Parser DOM Elements
|
|
14
|
+
const smartInput = document.getElementById('smartInput');
|
|
15
|
+
const smartParseBtn = document.getElementById('smartParseBtn');
|
|
16
|
+
|
|
17
|
+
// Proxy Input Elements
|
|
18
|
+
const proxyTypeRadios = document.getElementsByName('proxyType');
|
|
19
|
+
const proxyHostInput = document.getElementById('proxyHost');
|
|
20
|
+
const proxyPortInput = document.getElementById('proxyPort');
|
|
21
|
+
const proxyUserInput = document.getElementById('proxyUser');
|
|
22
|
+
const proxyPassInput = document.getElementById('proxyPass');
|
|
23
|
+
const togglePassBtn = document.getElementById('togglePassBtn');
|
|
24
|
+
|
|
25
|
+
// Fingerprint Shield Toggle Elements
|
|
26
|
+
const webrtcDisabledCheckbox = document.getElementById('webrtcDisabled');
|
|
27
|
+
const languagesEnabledCheckbox = document.getElementById('languagesEnabled');
|
|
28
|
+
const hardwareMaskingEnabledCheckbox = document.getElementById('hardwareMaskingEnabled');
|
|
29
|
+
const antiBotEnabledCheckbox = document.getElementById('antiBotEnabled');
|
|
30
|
+
|
|
31
|
+
// Timezone Elements
|
|
32
|
+
const timezoneEnabledCheckbox = document.getElementById('timezoneEnabled');
|
|
33
|
+
const spoofTimezoneInput = document.getElementById('spoofTimezone');
|
|
34
|
+
const detectTimezoneBtn = document.getElementById('detectTimezoneBtn');
|
|
35
|
+
const timezoneInputSection = document.getElementById('timezoneInputSection');
|
|
36
|
+
|
|
37
|
+
// Action & Status Elements
|
|
38
|
+
const saveApplyBtn = document.getElementById('saveApplyBtn');
|
|
39
|
+
const statusProxyDot = document.getElementById('statusProxyDot');
|
|
40
|
+
const statusProxyVal = document.getElementById('statusProxyVal');
|
|
41
|
+
const statusTzDot = document.getElementById('statusTzDot');
|
|
42
|
+
const statusTzVal = document.getElementById('statusTzVal');
|
|
43
|
+
|
|
44
|
+
// Live Diagnostic DOM Elements
|
|
45
|
+
const refreshDiagBtn = document.getElementById('refreshDiagBtn');
|
|
46
|
+
const openPingBtn = document.getElementById('openPingBtn');
|
|
47
|
+
const diagIp = document.getElementById('diagIp');
|
|
48
|
+
const diagGeo = document.getElementById('diagGeo');
|
|
49
|
+
const diagTz = document.getElementById('diagTz');
|
|
50
|
+
const diagWebrtc = document.getElementById('diagWebrtc');
|
|
51
|
+
|
|
52
|
+
// Profile Cloner DOM Elements
|
|
53
|
+
const exportBtn = document.getElementById('exportBtn');
|
|
54
|
+
const importTriggerBtn = document.getElementById('importTriggerBtn');
|
|
55
|
+
const importFileInput = document.getElementById('importFileInput');
|
|
56
|
+
const migrationStatus = document.getElementById('migrationStatus');
|
|
57
|
+
|
|
58
|
+
// Local state
|
|
59
|
+
const isProxyEnabled = true; // Permanently locked safe proxy mode
|
|
60
|
+
let isWindowMode = false;
|
|
61
|
+
|
|
62
|
+
// 1. Initialize UI with Saved Settings & Window States
|
|
63
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
64
|
+
detectWindowMode();
|
|
65
|
+
initTheme();
|
|
66
|
+
loadConfiguration();
|
|
67
|
+
setupEventListeners();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// 2. Window Mode Detection & Handlers
|
|
71
|
+
function detectWindowMode() {
|
|
72
|
+
isWindowMode = window.location.search.includes('mode=window');
|
|
73
|
+
|
|
74
|
+
if (isWindowMode) {
|
|
75
|
+
document.documentElement.classList.add('window-mode-active');
|
|
76
|
+
document.body.classList.add('window-mode-active');
|
|
77
|
+
openWindowBtn.classList.add('hidden');
|
|
78
|
+
closeWindowBtn.classList.remove('hidden');
|
|
79
|
+
} else {
|
|
80
|
+
openWindowBtn.classList.remove('hidden');
|
|
81
|
+
closeWindowBtn.classList.add('hidden');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 3. Theme Preferences
|
|
86
|
+
function initTheme() {
|
|
87
|
+
chrome.storage.local.get(['theme'], (result) => {
|
|
88
|
+
// Default to Light Mode (白天模式) on first load if theme is unset (undefined) or explicitly set to 'light'
|
|
89
|
+
if (result.theme === 'light' || result.theme === undefined) {
|
|
90
|
+
document.body.classList.add('light-mode');
|
|
91
|
+
} else {
|
|
92
|
+
document.body.classList.remove('light-mode');
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
themeToggleBtn.addEventListener('click', () => {
|
|
97
|
+
document.body.classList.toggle('light-mode');
|
|
98
|
+
const isLight = document.body.classList.contains('light-mode');
|
|
99
|
+
chrome.storage.local.set({ theme: isLight ? 'light' : 'dark' });
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 4. Load Configurations (With Safe Draft Recovery)
|
|
104
|
+
function loadConfiguration() {
|
|
105
|
+
chrome.storage.local.get([
|
|
106
|
+
'proxyConfig',
|
|
107
|
+
'timezoneEnabled',
|
|
108
|
+
'spoofTimezone',
|
|
109
|
+
'webrtcDisabled',
|
|
110
|
+
'languagesEnabled',
|
|
111
|
+
'hardwareMaskingEnabled',
|
|
112
|
+
'antiBotEnabled',
|
|
113
|
+
'formDraft'
|
|
114
|
+
], (data) => {
|
|
115
|
+
|
|
116
|
+
const configSource = data.formDraft || {};
|
|
117
|
+
const activeConfig = data.proxyConfig || {};
|
|
118
|
+
|
|
119
|
+
// 1. Populate proxy details
|
|
120
|
+
const activeType = configSource.type || activeConfig.type || 'HTTP';
|
|
121
|
+
for (const radio of proxyTypeRadios) {
|
|
122
|
+
if (radio.value === activeType) {
|
|
123
|
+
radio.checked = true;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
proxyHostInput.value = configSource.host !== undefined ? configSource.host : (activeConfig.host || '');
|
|
129
|
+
proxyPortInput.value = configSource.port !== undefined ? configSource.port : (activeConfig.port || '');
|
|
130
|
+
proxyUserInput.value = configSource.username !== undefined ? configSource.username : (activeConfig.username || '');
|
|
131
|
+
proxyPassInput.value = configSource.password !== undefined ? configSource.password : (activeConfig.password || '');
|
|
132
|
+
|
|
133
|
+
// 2. Populate Fingerprint Shields (default to true if undefined)
|
|
134
|
+
webrtcDisabledCheckbox.checked = configSource.webrtcDisabled !== undefined ? configSource.webrtcDisabled : (data.webrtcDisabled !== false);
|
|
135
|
+
languagesEnabledCheckbox.checked = configSource.languagesEnabled !== undefined ? configSource.languagesEnabled : (data.languagesEnabled !== false);
|
|
136
|
+
hardwareMaskingEnabledCheckbox.checked = configSource.hardwareMaskingEnabled !== undefined ? configSource.hardwareMaskingEnabled : (data.hardwareMaskingEnabled !== false);
|
|
137
|
+
antiBotEnabledCheckbox.checked = configSource.antiBotEnabled !== undefined ? configSource.antiBotEnabled : (data.antiBotEnabled !== false);
|
|
138
|
+
|
|
139
|
+
// 3. Populate Timezone details
|
|
140
|
+
const isTzEnabled = configSource.timezoneEnabled !== undefined ? configSource.timezoneEnabled : (data.timezoneEnabled !== false);
|
|
141
|
+
timezoneEnabledCheckbox.checked = isTzEnabled;
|
|
142
|
+
spoofTimezoneInput.value = configSource.spoofTimezone !== undefined ? configSource.spoofTimezone : (data.spoofTimezone || '');
|
|
143
|
+
|
|
144
|
+
// Toggle manual input section visibility
|
|
145
|
+
toggleTimezoneInputUI(isTzEnabled);
|
|
146
|
+
|
|
147
|
+
// 4. Update bottom status panel (Always displays the ACTIVE applied proxy status, not draft!)
|
|
148
|
+
updateStatusBadges(data.proxyConfig, data.timezoneEnabled !== false, data.spoofTimezone);
|
|
149
|
+
|
|
150
|
+
// 5. Run Live Diagnostics
|
|
151
|
+
runLiveDiagnostic();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 5. Setup DOM Event Listeners
|
|
156
|
+
function setupEventListeners() {
|
|
157
|
+
// Standalone Window Controls
|
|
158
|
+
openWindowBtn.addEventListener('click', () => {
|
|
159
|
+
chrome.windows.create({
|
|
160
|
+
url: chrome.runtime.getURL("popup.html?mode=window"),
|
|
161
|
+
type: "popup",
|
|
162
|
+
width: 1050,
|
|
163
|
+
height: 880
|
|
164
|
+
}, (win) => {
|
|
165
|
+
// Notify background worker about the standalone window ID to initiate front-focus tracking
|
|
166
|
+
chrome.runtime.sendMessage({ action: "registerStandaloneWindow", windowId: win.id });
|
|
167
|
+
});
|
|
168
|
+
window.close(); // Close the dropdown popup instantly to eliminate any transition lag!
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
closeWindowBtn.addEventListener('click', () => {
|
|
172
|
+
window.close();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Password visibility control
|
|
176
|
+
togglePassBtn.addEventListener('click', () => {
|
|
177
|
+
if (proxyPassInput.type === 'password') {
|
|
178
|
+
proxyPassInput.type = 'text';
|
|
179
|
+
togglePassBtn.textContent = '🙈';
|
|
180
|
+
togglePassBtn.title = '隐藏密码';
|
|
181
|
+
} else {
|
|
182
|
+
proxyPassInput.type = 'password';
|
|
183
|
+
togglePassBtn.textContent = '👁️';
|
|
184
|
+
togglePassBtn.title = '显示密码';
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Timezone switch listener
|
|
189
|
+
timezoneEnabledCheckbox.addEventListener('change', (e) => {
|
|
190
|
+
toggleTimezoneInputUI(e.target.checked);
|
|
191
|
+
saveFormDraft();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Auto-Detect Timezone Click
|
|
195
|
+
detectTimezoneBtn.addEventListener('click', handleTimezoneDetection);
|
|
196
|
+
|
|
197
|
+
// Save & Apply Click
|
|
198
|
+
saveApplyBtn.addEventListener('click', saveAndApplySettings);
|
|
199
|
+
|
|
200
|
+
// Diagnostic Click Triggers
|
|
201
|
+
refreshDiagBtn.addEventListener('click', () => {
|
|
202
|
+
runLiveDiagnostic();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
openPingBtn.addEventListener('click', () => {
|
|
206
|
+
if (typeof chrome !== 'undefined' && chrome.tabs && chrome.tabs.create) {
|
|
207
|
+
chrome.tabs.create({ url: 'https://ping0.cc/' });
|
|
208
|
+
} else {
|
|
209
|
+
window.open('https://ping0.cc/', '_blank');
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Profile Cloner Click Triggers
|
|
214
|
+
exportBtn.addEventListener('click', handleExportProfile);
|
|
215
|
+
importTriggerBtn.addEventListener('click', () => {
|
|
216
|
+
importFileInput.click();
|
|
217
|
+
});
|
|
218
|
+
importFileInput.addEventListener('change', handleImportProfile);
|
|
219
|
+
|
|
220
|
+
const destroyBtn = document.getElementById('destroyBtn');
|
|
221
|
+
if (destroyBtn) {
|
|
222
|
+
destroyBtn.addEventListener('click', handleDestroyProfile);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Smart Parser Click Trigger
|
|
226
|
+
if (smartParseBtn) {
|
|
227
|
+
smartParseBtn.addEventListener('click', handleSmartParse);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Draft triggers - Save form content immediately on input changes to prevent data loss!
|
|
231
|
+
const inputsToSave = [proxyHostInput, proxyPortInput, proxyUserInput, proxyPassInput, spoofTimezoneInput];
|
|
232
|
+
inputsToSave.forEach(input => {
|
|
233
|
+
input.addEventListener('input', saveFormDraft);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const togglesToSave = [webrtcDisabledCheckbox, languagesEnabledCheckbox, hardwareMaskingEnabledCheckbox, antiBotEnabledCheckbox];
|
|
237
|
+
togglesToSave.forEach(toggle => {
|
|
238
|
+
toggle.addEventListener('change', saveFormDraft);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
for (const radio of proxyTypeRadios) {
|
|
242
|
+
radio.addEventListener('change', saveFormDraft);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 6. Form Draft Auto-Save Handler
|
|
247
|
+
function saveFormDraft() {
|
|
248
|
+
let selectedType = 'HTTP';
|
|
249
|
+
for (const radio of proxyTypeRadios) {
|
|
250
|
+
if (radio.checked) {
|
|
251
|
+
selectedType = radio.value;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const draft = {
|
|
257
|
+
type: selectedType,
|
|
258
|
+
host: proxyHostInput.value.trim(),
|
|
259
|
+
port: proxyPortInput.value.trim(),
|
|
260
|
+
username: proxyUserInput.value.trim(),
|
|
261
|
+
password: proxyPassInput.value,
|
|
262
|
+
timezoneEnabled: timezoneEnabledCheckbox.checked,
|
|
263
|
+
spoofTimezone: spoofTimezoneInput.value.trim(),
|
|
264
|
+
webrtcDisabled: webrtcDisabledCheckbox.checked,
|
|
265
|
+
languagesEnabled: languagesEnabledCheckbox.checked,
|
|
266
|
+
hardwareMaskingEnabled: hardwareMaskingEnabledCheckbox.checked,
|
|
267
|
+
antiBotEnabled: antiBotEnabledCheckbox.checked
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
chrome.storage.local.set({ formDraft: draft });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 7. Toggle Timezone manual configuration block
|
|
274
|
+
function toggleTimezoneInputUI(enabled) {
|
|
275
|
+
if (enabled) {
|
|
276
|
+
timezoneInputSection.style.opacity = '1';
|
|
277
|
+
timezoneInputSection.style.pointerEvents = 'auto';
|
|
278
|
+
} else {
|
|
279
|
+
timezoneInputSection.style.opacity = '0.5';
|
|
280
|
+
timezoneInputSection.style.pointerEvents = 'none';
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 8. Timezone Auto Detection with Multi-API Fallback Chain
|
|
285
|
+
function handleTimezoneDetection() {
|
|
286
|
+
const ipVal = proxyHostInput.value.trim();
|
|
287
|
+
const spinner = detectTimezoneBtn.querySelector('.loading-spinner');
|
|
288
|
+
const btnIcon = detectTimezoneBtn.querySelector('.icon-svg');
|
|
289
|
+
const btnText = detectTimezoneBtn.querySelector('span');
|
|
290
|
+
|
|
291
|
+
spinner.classList.remove('hidden');
|
|
292
|
+
btnIcon.classList.add('hidden');
|
|
293
|
+
btnText.textContent = "正在获取时区...";
|
|
294
|
+
detectTimezoneBtn.disabled = true;
|
|
295
|
+
|
|
296
|
+
detectTimezoneChain(ipVal)
|
|
297
|
+
.then(timezone => {
|
|
298
|
+
spoofTimezoneInput.value = timezone;
|
|
299
|
+
|
|
300
|
+
btnText.textContent = `成功匹配: ${timezone}`;
|
|
301
|
+
detectTimezoneBtn.style.borderColor = 'var(--success)';
|
|
302
|
+
detectTimezoneBtn.style.color = 'var(--success)';
|
|
303
|
+
|
|
304
|
+
timezoneEnabledCheckbox.checked = true;
|
|
305
|
+
toggleTimezoneInputUI(true);
|
|
306
|
+
|
|
307
|
+
saveFormDraft();
|
|
308
|
+
|
|
309
|
+
setTimeout(() => {
|
|
310
|
+
resetDetectButton();
|
|
311
|
+
}, 2500);
|
|
312
|
+
})
|
|
313
|
+
.catch(err => {
|
|
314
|
+
console.log("OmniFlow: All timezone APIs failed: ", err);
|
|
315
|
+
|
|
316
|
+
btnText.textContent = "时区获取失败,请手动输入";
|
|
317
|
+
detectTimezoneBtn.style.borderColor = 'var(--danger)';
|
|
318
|
+
detectTimezoneBtn.style.color = 'var(--danger)';
|
|
319
|
+
|
|
320
|
+
setTimeout(() => {
|
|
321
|
+
resetDetectButton();
|
|
322
|
+
}, 3000);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
function resetDetectButton() {
|
|
326
|
+
spinner.classList.add('hidden');
|
|
327
|
+
btnIcon.classList.remove('hidden');
|
|
328
|
+
btnText.textContent = "自动识别 IP 时区";
|
|
329
|
+
detectTimezoneBtn.style.borderColor = '';
|
|
330
|
+
detectTimezoneBtn.style.color = '';
|
|
331
|
+
detectTimezoneBtn.disabled = false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function detectTimezoneChain(ip) {
|
|
336
|
+
const apiUrls = [
|
|
337
|
+
ip ? `https://freeipapi.com/api/json/${ip}` : 'https://freeipapi.com/api/json',
|
|
338
|
+
ip ? `https://api.ip.sb/geoip/${ip}` : 'https://api.ip.sb/geoip',
|
|
339
|
+
ip ? `https://ipapi.co/${ip}/json/` : 'https://ipapi.co/json/',
|
|
340
|
+
ip ? `https://ipinfo.io/${ip}/json` : 'https://ipinfo.io/json',
|
|
341
|
+
ip ? `http://ip-api.com/json/${ip}` : 'http://ip-api.com/json/'
|
|
342
|
+
];
|
|
343
|
+
|
|
344
|
+
return new Promise((resolve, reject) => {
|
|
345
|
+
let index = 0;
|
|
346
|
+
|
|
347
|
+
function tryNextApi() {
|
|
348
|
+
if (index >= apiUrls.length) {
|
|
349
|
+
reject(new Error("All fallback GeoIP services failed."));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const url = apiUrls[index];
|
|
354
|
+
fetch(url)
|
|
355
|
+
.then(res => {
|
|
356
|
+
if (!res.ok) throw new Error(`HTTP Error ${res.status}`);
|
|
357
|
+
return res.json();
|
|
358
|
+
})
|
|
359
|
+
.then(data => {
|
|
360
|
+
if (data && (data.timezone || data.timeZone)) {
|
|
361
|
+
resolve(data.timezone || data.timeZone);
|
|
362
|
+
} else {
|
|
363
|
+
throw new Error("No timezone key in JSON");
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
.catch(err => {
|
|
367
|
+
index++;
|
|
368
|
+
tryNextApi();
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
tryNextApi();
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 8.5 Smart Proxy Parser and Auto-timezone synchronization functions
|
|
377
|
+
function handleSmartParse() {
|
|
378
|
+
const rawStr = smartInput.value.trim();
|
|
379
|
+
if (!rawStr) {
|
|
380
|
+
alert("请先粘贴需要解析的代理信息!");
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const parsed = parseProxyString(rawStr);
|
|
385
|
+
if (!parsed || !parsed.host) {
|
|
386
|
+
alert("无法解析该格式,请提供诸如 IP:端口 或 IP:端口:账号:密码 的有效代理字符串。");
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// 1. Fill Proxy Type (HTTP / SOCKS5)
|
|
391
|
+
if (parsed.type) {
|
|
392
|
+
for (const radio of proxyTypeRadios) {
|
|
393
|
+
if (radio.value === parsed.type) {
|
|
394
|
+
radio.checked = true;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// 2. Populate input fields
|
|
401
|
+
proxyHostInput.value = parsed.host;
|
|
402
|
+
proxyPortInput.value = parsed.port || "";
|
|
403
|
+
proxyUserInput.value = parsed.username || "";
|
|
404
|
+
proxyPassInput.value = parsed.password || "";
|
|
405
|
+
|
|
406
|
+
// 3. UI interaction feedback
|
|
407
|
+
const originalBtnText = smartParseBtn.querySelector('span').textContent;
|
|
408
|
+
smartParseBtn.disabled = true;
|
|
409
|
+
smartParseBtn.querySelector('span').textContent = "解析成功";
|
|
410
|
+
smartParseBtn.style.background = 'var(--success)';
|
|
411
|
+
smartParseBtn.style.borderColor = 'var(--success)';
|
|
412
|
+
smartParseBtn.style.color = '#ffffff';
|
|
413
|
+
|
|
414
|
+
// 4. Automatically trigger timezone detection
|
|
415
|
+
setTimeout(() => {
|
|
416
|
+
// Reset smart parse button
|
|
417
|
+
smartParseBtn.disabled = false;
|
|
418
|
+
smartParseBtn.querySelector('span').textContent = originalBtnText;
|
|
419
|
+
smartParseBtn.style.background = '';
|
|
420
|
+
smartParseBtn.style.borderColor = '';
|
|
421
|
+
smartParseBtn.style.color = '';
|
|
422
|
+
|
|
423
|
+
// Clear input to avoid crowded look
|
|
424
|
+
smartInput.value = '';
|
|
425
|
+
|
|
426
|
+
// Automatically trigger background timezone API detection based on the new IP
|
|
427
|
+
handleTimezoneDetection();
|
|
428
|
+
}, 1000);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function parseProxyString(str) {
|
|
432
|
+
str = str.trim();
|
|
433
|
+
if (!str) return null;
|
|
434
|
+
|
|
435
|
+
let type = null;
|
|
436
|
+
let host = "";
|
|
437
|
+
let port = "";
|
|
438
|
+
let username = "";
|
|
439
|
+
let password = "";
|
|
440
|
+
|
|
441
|
+
// 1. Detect protocols (http://, socks5://, socks4://)
|
|
442
|
+
const protocolMatch = str.match(/^(https?|socks5|socks4):\/\//i);
|
|
443
|
+
if (protocolMatch) {
|
|
444
|
+
const proto = protocolMatch[1].toUpperCase();
|
|
445
|
+
type = proto.startsWith("SOCKS") ? "SOCKS5" : "HTTP";
|
|
446
|
+
str = str.substring(protocolMatch[0].length);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 2. Check for username:password@host:port format
|
|
450
|
+
if (str.includes("@")) {
|
|
451
|
+
const atParts = str.split("@");
|
|
452
|
+
const userPassPart = atParts[0];
|
|
453
|
+
const hostPortPart = atParts[1];
|
|
454
|
+
|
|
455
|
+
const upSubParts = userPassPart.split(":");
|
|
456
|
+
username = upSubParts[0] || "";
|
|
457
|
+
password = upSubParts.slice(1).join(":") || "";
|
|
458
|
+
|
|
459
|
+
const hpSubParts = hostPortPart.split(":");
|
|
460
|
+
host = hpSubParts[0] || "";
|
|
461
|
+
port = hpSubParts[1] || "";
|
|
462
|
+
} else {
|
|
463
|
+
// 3. Try to split by colons or spaces
|
|
464
|
+
let parts = [];
|
|
465
|
+
if (str.includes(":")) {
|
|
466
|
+
parts = str.split(":");
|
|
467
|
+
} else {
|
|
468
|
+
parts = str.split(/\s+/);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (parts.length >= 4) {
|
|
472
|
+
// Format: host:port:username:password
|
|
473
|
+
host = parts[0];
|
|
474
|
+
port = parts[1];
|
|
475
|
+
username = parts[2];
|
|
476
|
+
password = parts.slice(3).join(":");
|
|
477
|
+
} else if (parts.length === 3) {
|
|
478
|
+
// Format: host:port:username
|
|
479
|
+
host = parts[0];
|
|
480
|
+
port = parts[1];
|
|
481
|
+
username = parts[2];
|
|
482
|
+
} else if (parts.length === 2) {
|
|
483
|
+
// Format: host:port
|
|
484
|
+
host = parts[0];
|
|
485
|
+
port = parts[1];
|
|
486
|
+
} else {
|
|
487
|
+
host = str;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
host = host.trim();
|
|
492
|
+
port = port.trim();
|
|
493
|
+
username = username.trim();
|
|
494
|
+
password = password.trim();
|
|
495
|
+
|
|
496
|
+
// Handle username:password:host:port fallback if port is last and numeric, but part 2 is not
|
|
497
|
+
if (port && !/^\d+$/.test(port)) {
|
|
498
|
+
const parts = str.split(":");
|
|
499
|
+
if (parts.length === 4 && !/^\d+$/.test(parts[1]) && /^\d+$/.test(parts[3])) {
|
|
500
|
+
username = parts[0];
|
|
501
|
+
password = parts[1];
|
|
502
|
+
host = parts[2];
|
|
503
|
+
port = parts[3];
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return { type, host, port, username, password };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 9. Real-time Env Diagnostic Center (ping0.cc simulator)
|
|
511
|
+
function runLiveDiagnostic() {
|
|
512
|
+
diagIp.textContent = "正在检测...";
|
|
513
|
+
diagIp.className = "diag-value info";
|
|
514
|
+
diagGeo.textContent = "正在分析...";
|
|
515
|
+
diagGeo.className = "diag-value info";
|
|
516
|
+
diagTz.textContent = "同步检测中...";
|
|
517
|
+
diagTz.className = "diag-value info";
|
|
518
|
+
|
|
519
|
+
const isWebrtcProtected = webrtcDisabledCheckbox.checked;
|
|
520
|
+
if (isWebrtcProtected) {
|
|
521
|
+
diagWebrtc.textContent = "🛡️ 安全锁定 (零泄露)";
|
|
522
|
+
diagWebrtc.className = "diag-value success";
|
|
523
|
+
} else {
|
|
524
|
+
diagWebrtc.textContent = "⚠️ 未防护 (泄露局域网 IP)";
|
|
525
|
+
diagWebrtc.className = "diag-value warning";
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const targetTz = spoofTimezoneInput.value.trim();
|
|
529
|
+
|
|
530
|
+
fetch(`https://ipinfo.io/json?nocache=${Date.now()}`)
|
|
531
|
+
.then(res => {
|
|
532
|
+
if (!res.ok) throw new Error('Proxy unreachable');
|
|
533
|
+
return res.json();
|
|
534
|
+
})
|
|
535
|
+
.then(data => {
|
|
536
|
+
if (data && data.ip) {
|
|
537
|
+
diagIp.textContent = data.ip;
|
|
538
|
+
diagIp.className = "diag-value success";
|
|
539
|
+
|
|
540
|
+
diagGeo.textContent = `${data.city || ''}, ${data.country || ''}`;
|
|
541
|
+
diagGeo.className = "diag-value success";
|
|
542
|
+
|
|
543
|
+
const browserTz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
544
|
+
const ipTz = data.timezone || '';
|
|
545
|
+
|
|
546
|
+
if (browserTz === ipTz) {
|
|
547
|
+
diagTz.textContent = `${browserTz} (✅ 100% 对齐成功)`;
|
|
548
|
+
diagTz.className = "diag-value success";
|
|
549
|
+
} else {
|
|
550
|
+
diagTz.textContent = `系统: ${browserTz} vs IP: ${ipTz}`;
|
|
551
|
+
diagTz.className = "diag-value warning";
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
.catch(err => {
|
|
556
|
+
console.log("OmniFlow Diagnostic: Outbound network blocked. Leak Lock is doing its job:", err.message);
|
|
557
|
+
diagIp.textContent = "🔒 物理阻断 (保护锁已拦截)";
|
|
558
|
+
diagIp.className = "diag-value warning";
|
|
559
|
+
diagGeo.textContent = "—";
|
|
560
|
+
diagGeo.className = "diag-value";
|
|
561
|
+
diagTz.textContent = "—";
|
|
562
|
+
diagTz.className = "diag-value";
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// 10. Save and Apply Configurations
|
|
567
|
+
function saveAndApplySettings() {
|
|
568
|
+
let selectedType = 'HTTP';
|
|
569
|
+
for (const radio of proxyTypeRadios) {
|
|
570
|
+
if (radio.checked) {
|
|
571
|
+
selectedType = radio.value;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const hostVal = proxyHostInput.value.trim();
|
|
577
|
+
const portVal = proxyPortInput.value.trim();
|
|
578
|
+
const userVal = proxyUserInput.value.trim();
|
|
579
|
+
const passVal = proxyPassInput.value;
|
|
580
|
+
|
|
581
|
+
const isTzEnabled = timezoneEnabledCheckbox.checked;
|
|
582
|
+
const tzVal = spoofTimezoneInput.value.trim();
|
|
583
|
+
|
|
584
|
+
const isWebrtcDisabled = webrtcDisabledCheckbox.checked;
|
|
585
|
+
const isLanguagesEnabled = languagesEnabledCheckbox.checked;
|
|
586
|
+
const isHardwareMaskingEnabled = hardwareMaskingEnabledCheckbox.checked;
|
|
587
|
+
const isAntiBotEnabled = antiBotEnabledCheckbox.checked;
|
|
588
|
+
|
|
589
|
+
if (hostVal && !portVal) {
|
|
590
|
+
alert("请输入有效的代理端口!");
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const proxyConfig = {
|
|
595
|
+
type: selectedType,
|
|
596
|
+
host: hostVal,
|
|
597
|
+
port: portVal,
|
|
598
|
+
username: userVal,
|
|
599
|
+
password: passVal
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
const originalBtnText = saveApplyBtn.querySelector('span').textContent;
|
|
603
|
+
saveApplyBtn.disabled = true;
|
|
604
|
+
|
|
605
|
+
// Proactive Auto-Tz Resolver: If timezone spoofing is toggled ON but the input box is left empty,
|
|
606
|
+
// we automatically invoke the fallback resolver chain in the background based on the proxy host!
|
|
607
|
+
if (isTzEnabled && !tzVal && hostVal) {
|
|
608
|
+
saveApplyBtn.querySelector('span').textContent = "正在自动获取代理IP时区...";
|
|
609
|
+
detectTimezoneChain(hostVal)
|
|
610
|
+
.then(detectedTz => {
|
|
611
|
+
spoofTimezoneInput.value = detectedTz;
|
|
612
|
+
proceedWithSave(detectedTz);
|
|
613
|
+
})
|
|
614
|
+
.catch(err => {
|
|
615
|
+
console.log("OmniFlow Auto-Tz: Failed to resolve, falling back to empty:", err);
|
|
616
|
+
proceedWithSave("");
|
|
617
|
+
});
|
|
618
|
+
} else {
|
|
619
|
+
saveApplyBtn.querySelector('span').textContent = "正在保存并生效...";
|
|
620
|
+
proceedWithSave(tzVal);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function proceedWithSave(finalTz) {
|
|
624
|
+
chrome.storage.local.set({
|
|
625
|
+
proxyEnabled: isProxyEnabled,
|
|
626
|
+
proxyConfig: proxyConfig,
|
|
627
|
+
timezoneEnabled: isTzEnabled,
|
|
628
|
+
spoofTimezone: finalTz,
|
|
629
|
+
webrtcDisabled: isWebrtcDisabled,
|
|
630
|
+
languagesEnabled: isLanguagesEnabled,
|
|
631
|
+
hardwareMaskingEnabled: isHardwareMaskingEnabled,
|
|
632
|
+
antiBotEnabled: isAntiBotEnabled
|
|
633
|
+
}, () => {
|
|
634
|
+
saveFormDraft();
|
|
635
|
+
|
|
636
|
+
updateStatusBadges(proxyConfig, isTzEnabled, finalTz);
|
|
637
|
+
|
|
638
|
+
setTimeout(() => {
|
|
639
|
+
runLiveDiagnostic();
|
|
640
|
+
}, 800);
|
|
641
|
+
|
|
642
|
+
setTimeout(() => {
|
|
643
|
+
saveApplyBtn.querySelector('span').textContent = "✨ 盾牌保护已就绪!";
|
|
644
|
+
saveApplyBtn.style.background = 'var(--success)';
|
|
645
|
+
saveApplyBtn.style.borderColor = 'var(--success)';
|
|
646
|
+
saveApplyBtn.style.boxShadow = '0 0 15px var(--success-glow)';
|
|
647
|
+
|
|
648
|
+
setTimeout(() => {
|
|
649
|
+
saveApplyBtn.querySelector('span').textContent = originalBtnText;
|
|
650
|
+
saveApplyBtn.style.background = '';
|
|
651
|
+
saveApplyBtn.style.borderColor = '';
|
|
652
|
+
saveApplyBtn.style.boxShadow = '';
|
|
653
|
+
saveApplyBtn.disabled = false;
|
|
654
|
+
}, 1500);
|
|
655
|
+
}, 500);
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Helper to update the status badges at the bottom of the popup
|
|
661
|
+
function updateStatusBadges(proxyConfig, isTzEnabled, tzVal) {
|
|
662
|
+
if (!statusProxyDot || !statusProxyVal || !statusTzDot || !statusTzVal) return;
|
|
663
|
+
|
|
664
|
+
// 1. Update Proxy Badge
|
|
665
|
+
if (proxyConfig && proxyConfig.host && proxyConfig.port) {
|
|
666
|
+
statusProxyDot.style.background = 'var(--success)';
|
|
667
|
+
statusProxyDot.style.boxShadow = '0 0 8px var(--success-glow)';
|
|
668
|
+
statusProxyVal.textContent = `${proxyConfig.type || 'HTTP'}://${proxyConfig.host}:${proxyConfig.port}`;
|
|
669
|
+
} else {
|
|
670
|
+
// Under IP Leak Lock, unconfigured network is safely blocked
|
|
671
|
+
statusProxyDot.style.background = 'var(--warning)';
|
|
672
|
+
statusProxyDot.style.boxShadow = '0 0 8px var(--warning-glow)';
|
|
673
|
+
statusProxyVal.textContent = '未配置(安全锁拦截中)';
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// 2. Update Timezone Badge
|
|
677
|
+
if (isTzEnabled && tzVal) {
|
|
678
|
+
statusTzDot.style.background = 'var(--success)';
|
|
679
|
+
statusTzDot.style.boxShadow = '0 0 8px var(--success-glow)';
|
|
680
|
+
statusTzVal.textContent = tzVal;
|
|
681
|
+
statusTzVal.title = tzVal;
|
|
682
|
+
} else {
|
|
683
|
+
statusTzDot.style.background = 'var(--warning)';
|
|
684
|
+
statusTzDot.style.boxShadow = '0 0 8px var(--warning-glow)';
|
|
685
|
+
statusTzVal.textContent = '系统默认';
|
|
686
|
+
statusTzVal.title = '系统默认';
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// 11. Profile Sideloading Migration Cloner Engine (Cookies & settings export/import)
|
|
691
|
+
function handleExportProfile() {
|
|
692
|
+
migrationStatus.classList.remove('hidden', 'success', 'warning');
|
|
693
|
+
migrationStatus.textContent = "正在扫描并打包全网 Sessions...";
|
|
694
|
+
migrationStatus.style.color = "var(--text-muted)";
|
|
695
|
+
|
|
696
|
+
// Step 1: Capture all local extension storage settings
|
|
697
|
+
chrome.storage.local.get(null, (storageData) => {
|
|
698
|
+
if (storageData.formDraft) {
|
|
699
|
+
delete storageData.formDraft;
|
|
700
|
+
}
|
|
701
|
+
delete storageData.dipclawReady;
|
|
702
|
+
delete storageData.standaloneWindowId;
|
|
703
|
+
|
|
704
|
+
// Step 2: Query ALL browser cookies in the current Profile!
|
|
705
|
+
chrome.cookies.getAll({}, (cookiesList) => {
|
|
706
|
+
if (chrome.runtime.lastError) {
|
|
707
|
+
showMigrationFeedback(`❌ 无法读取 Cookies: ${chrome.runtime.lastError.message}`, 'warning');
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Step 3: Bundle everything into a single secure cloner payload
|
|
712
|
+
const clonerPayload = {
|
|
713
|
+
app: "OmniFlow",
|
|
714
|
+
version: "1.0.0",
|
|
715
|
+
timestamp: Date.now(),
|
|
716
|
+
extensionStorage: storageData,
|
|
717
|
+
cookies: cookiesList
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
try {
|
|
721
|
+
// Step 4: Serialize clonerPayload to JSON Blob
|
|
722
|
+
const blob = new Blob([JSON.stringify(clonerPayload, null, 2)], { type: "application/json" });
|
|
723
|
+
|
|
724
|
+
// Retrieve IP and Port to name the file IP:Port.json (e.g. 64.50.132.240:8080.json)
|
|
725
|
+
const ip = proxyHostInput.value.trim() || "127.0.0.1";
|
|
726
|
+
const port = proxyPortInput.value.trim() || "65535";
|
|
727
|
+
|
|
728
|
+
// Use the IP_Port format (e.g. 64.50.132.240_8080.json)
|
|
729
|
+
// Note: The chrome.downloads API has a strict security validator that hard-rejects colons (:),
|
|
730
|
+
// throwing a hard "Invalid filename" error. An underscore is the industry-standard safe separator.
|
|
731
|
+
const filename = `${ip}_${port}.json`;
|
|
732
|
+
|
|
733
|
+
const reader = new FileReader();
|
|
734
|
+
reader.onload = function() {
|
|
735
|
+
const dataUrl = reader.result;
|
|
736
|
+
|
|
737
|
+
// Programmatically download and directly OVERWRITE duplicates inside the user's downloads folder!
|
|
738
|
+
chrome.downloads.download({
|
|
739
|
+
url: dataUrl,
|
|
740
|
+
filename: filename,
|
|
741
|
+
conflictAction: "overwrite", // Direct silent overwrite of existing backups!
|
|
742
|
+
saveAs: false // Download silently without throwing dialog friction
|
|
743
|
+
}, (downloadId) => {
|
|
744
|
+
if (chrome.runtime.lastError) {
|
|
745
|
+
showMigrationFeedback(`❌ 备份保存失败: ${chrome.runtime.lastError.message}`, 'warning');
|
|
746
|
+
} else {
|
|
747
|
+
showMigrationFeedback(`✅ 备份打包成功!已覆盖并存为: ${filename}`, 'success');
|
|
748
|
+
|
|
749
|
+
// Trigger Developer Server Upload Hook!
|
|
750
|
+
uploadProfileToServer(clonerPayload);
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
};
|
|
754
|
+
reader.readAsDataURL(blob);
|
|
755
|
+
|
|
756
|
+
} catch (err) {
|
|
757
|
+
showMigrationFeedback(`❌ 打包失败: ${err.message}`, 'warning');
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function handleImportProfile(event) {
|
|
764
|
+
const file = event.target.files[0];
|
|
765
|
+
if (!file) return;
|
|
766
|
+
|
|
767
|
+
migrationStatus.classList.remove('hidden', 'success', 'warning');
|
|
768
|
+
migrationStatus.textContent = "正在解析环境备份包...";
|
|
769
|
+
migrationStatus.style.color = "var(--text-muted)";
|
|
770
|
+
|
|
771
|
+
const reader = new FileReader();
|
|
772
|
+
reader.onload = (e) => {
|
|
773
|
+
try {
|
|
774
|
+
const payload = JSON.parse(e.target.result);
|
|
775
|
+
|
|
776
|
+
// Basic signature validation
|
|
777
|
+
if (payload.app !== "OmniFlow" || !payload.extensionStorage || !payload.cookies) {
|
|
778
|
+
showMigrationFeedback("❌ 无效的 OmniFlow 备份包!请还原正确的配置文件。", "warning");
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Step 1: CLEAR ALL EXISTING COOKIES IN THE CURRENT PROFILE (Ultimate Clean Overwrite)
|
|
783
|
+
// This allows importing a new file to cleanly overwrite and erase any wrong previous imports!
|
|
784
|
+
migrationStatus.textContent = "正在全面清理旧分身 Cookies 以防冲突...";
|
|
785
|
+
|
|
786
|
+
chrome.cookies.getAll({}, (allCookies) => {
|
|
787
|
+
const clearPromises = allCookies.map(c => {
|
|
788
|
+
return new Promise((resolveClear) => {
|
|
789
|
+
try {
|
|
790
|
+
const domainName = c.domain.replace(/^\./, "");
|
|
791
|
+
const protocol = c.secure ? "https://" : "http://";
|
|
792
|
+
const cookieUrl = protocol + domainName + c.path;
|
|
793
|
+
|
|
794
|
+
chrome.cookies.remove({ url: cookieUrl, name: c.name }, () => {
|
|
795
|
+
resolveCookieWarning();
|
|
796
|
+
resolveClear();
|
|
797
|
+
});
|
|
798
|
+
} catch (err) {
|
|
799
|
+
resolveClear();
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
Promise.all(clearPromises).then(() => {
|
|
805
|
+
migrationStatus.textContent = "正在克隆全套防关联配置...";
|
|
806
|
+
|
|
807
|
+
// Step 2: Restore Extension Configurations
|
|
808
|
+
chrome.storage.local.set(payload.extensionStorage, () => {
|
|
809
|
+
|
|
810
|
+
migrationStatus.textContent = `正在恢复 ${payload.cookies.length} 个全新免密 Sessions...`;
|
|
811
|
+
|
|
812
|
+
// Step 3: Inject the new Cookies
|
|
813
|
+
const cookiePromises = payload.cookies.map(cookie => {
|
|
814
|
+
return new Promise((resolveCookie) => {
|
|
815
|
+
try {
|
|
816
|
+
const domainName = cookie.domain.replace(/^\./, "");
|
|
817
|
+
const protocol = cookie.secure ? "https://" : "http://";
|
|
818
|
+
const cookieUrl = protocol + domainName + cookie.path;
|
|
819
|
+
|
|
820
|
+
const setDetails = {
|
|
821
|
+
url: cookieUrl,
|
|
822
|
+
name: cookie.name,
|
|
823
|
+
value: cookie.value,
|
|
824
|
+
domain: cookie.domain,
|
|
825
|
+
path: cookie.path,
|
|
826
|
+
secure: cookie.secure,
|
|
827
|
+
httpOnly: cookie.httpOnly,
|
|
828
|
+
sameSite: cookie.sameSite,
|
|
829
|
+
expirationDate: cookie.expirationDate
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
if (cookie.session || !cookie.expirationDate) {
|
|
833
|
+
delete setDetails.expirationDate;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
chrome.cookies.set(setDetails, (res) => {
|
|
837
|
+
if (chrome.runtime.lastError) {
|
|
838
|
+
console.log("OmniFlow Cookie Restorer:", chrome.runtime.lastError.message);
|
|
839
|
+
}
|
|
840
|
+
resolveCookie();
|
|
841
|
+
});
|
|
842
|
+
} catch (err) {
|
|
843
|
+
resolveCookie();
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
Promise.all(cookiePromises).then(() => {
|
|
849
|
+
// Synchronize UI Form fields
|
|
850
|
+
loadConfiguration();
|
|
851
|
+
|
|
852
|
+
// Reset file picker
|
|
853
|
+
importFileInput.value = '';
|
|
854
|
+
|
|
855
|
+
showMigrationFeedback(`🎉 还原成功!已清空旧环境,并重新克隆导入 ${payload.cookies.length} 个 Cookies。请刷新页面!`, "success");
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
} catch (err) {
|
|
862
|
+
showMigrationFeedback(`❌ 解析还原失败: ${err.message}`, "warning");
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
reader.readAsText(file);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function handleDestroyProfile() {
|
|
870
|
+
if (!confirm("⚠️ 您确定要一键安全重置并彻底销毁该分身的所有数据吗?此操作将立即清空当前分身保存的代理配置、防关联设置以及全网所有已登录的网站会话(Cookies)!该操作是不可逆的。")) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
migrationStatus.classList.remove('hidden', 'success', 'warning');
|
|
875
|
+
migrationStatus.textContent = "正在执行一键安全重置与销毁...";
|
|
876
|
+
migrationStatus.style.color = "var(--text-muted)";
|
|
877
|
+
|
|
878
|
+
// Step 1: Clear all cookies in the browser profile
|
|
879
|
+
chrome.cookies.getAll({}, (allCookies) => {
|
|
880
|
+
const clearPromises = allCookies.map(c => {
|
|
881
|
+
return new Promise((resolveClear) => {
|
|
882
|
+
try {
|
|
883
|
+
const domainName = c.domain.replace(/^\./, "");
|
|
884
|
+
const protocol = c.secure ? "https://" : "http://";
|
|
885
|
+
const cookieUrl = protocol + domainName + c.path;
|
|
886
|
+
|
|
887
|
+
chrome.cookies.remove({ url: cookieUrl, name: c.name }, () => {
|
|
888
|
+
resolveCookieWarning();
|
|
889
|
+
resolveClear();
|
|
890
|
+
});
|
|
891
|
+
} catch (err) {
|
|
892
|
+
resolveClear();
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
Promise.all(clearPromises).then(() => {
|
|
898
|
+
// Step 2: Clear chrome extension storage local settings
|
|
899
|
+
chrome.storage.local.clear(() => {
|
|
900
|
+
if (chrome.runtime.lastError) {
|
|
901
|
+
showMigrationFeedback(`❌ 销毁部分数据时出错: ${chrome.runtime.lastError.message}`, "warning");
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// Step 3: Reset UI fields to default
|
|
906
|
+
proxyHostInput.value = '';
|
|
907
|
+
proxyPortInput.value = '';
|
|
908
|
+
proxyUserInput.value = '';
|
|
909
|
+
proxyPassInput.value = '';
|
|
910
|
+
|
|
911
|
+
webrtcDisabledCheckbox.checked = true;
|
|
912
|
+
languagesEnabledCheckbox.checked = true;
|
|
913
|
+
hardwareMaskingEnabledCheckbox.checked = true;
|
|
914
|
+
antiBotEnabledCheckbox.checked = true;
|
|
915
|
+
timezoneEnabledCheckbox.checked = true;
|
|
916
|
+
spoofTimezoneInput.value = '';
|
|
917
|
+
toggleTimezoneInputUI(true);
|
|
918
|
+
|
|
919
|
+
// Reset radio buttons to HTTP default
|
|
920
|
+
for (const radio of proxyTypeRadios) {
|
|
921
|
+
radio.checked = (radio.value === 'HTTP');
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Step 4: Re-initialize default clean settings state
|
|
925
|
+
chrome.storage.local.set({
|
|
926
|
+
proxyEnabled: true,
|
|
927
|
+
timezoneEnabled: true,
|
|
928
|
+
webrtcDisabled: true,
|
|
929
|
+
languagesEnabled: true,
|
|
930
|
+
hardwareMaskingEnabled: true,
|
|
931
|
+
antiBotEnabled: true
|
|
932
|
+
}, () => {
|
|
933
|
+
// Update status badges and diagnostic reporting to show clear/leak lock state
|
|
934
|
+
updateStatusBadges(null, true, '');
|
|
935
|
+
runLiveDiagnostic();
|
|
936
|
+
showMigrationFeedback("🎉 一键彻底重置与销毁成功!所有Cookies和指纹配置已被安全抹除。", "success");
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function showMigrationFeedback(msg, type) {
|
|
944
|
+
migrationStatus.classList.remove('hidden', 'success', 'warning');
|
|
945
|
+
migrationStatus.textContent = msg;
|
|
946
|
+
migrationStatus.classList.add(type);
|
|
947
|
+
if (type === 'success') {
|
|
948
|
+
migrationStatus.style.color = 'var(--success)';
|
|
949
|
+
} else if (type === 'warning') {
|
|
950
|
+
migrationStatus.style.color = 'var(--danger)';
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// System cookie warning resolver
|
|
955
|
+
function resolveCookieWarning() {
|
|
956
|
+
if (chrome.runtime.lastError) {
|
|
957
|
+
// Muted
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// ========================================================
|
|
962
|
+
// 12. DEVELOPER EXTENSIBLE SERVER HOOKS (SaaS Profile Sync)
|
|
963
|
+
// ========================================================
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Developer Hook: Auto-upload profile cloner backup package to your centralized server
|
|
967
|
+
* @param {Object} clonerPayload Contains { extensionStorage: {}, cookies: [] }
|
|
968
|
+
*/
|
|
969
|
+
function uploadProfileToServer(clonerPayload) {
|
|
970
|
+
console.log("OmniFlow Developer Hook: uploadProfileToServer triggered.");
|
|
971
|
+
|
|
972
|
+
// Future implementation:
|
|
973
|
+
/*
|
|
974
|
+
const SERVER_API_ENDPOINT = "https://your-api.com/profiles/sync";
|
|
975
|
+
fetch(SERVER_API_ENDPOINT, {
|
|
976
|
+
method: "POST",
|
|
977
|
+
headers: {
|
|
978
|
+
"Content-Type": "application/json",
|
|
979
|
+
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
|
|
980
|
+
},
|
|
981
|
+
body: JSON.stringify({
|
|
982
|
+
profileId: "profile_001", // Or retrieve dynamically
|
|
983
|
+
data: clonerPayload
|
|
984
|
+
})
|
|
985
|
+
})
|
|
986
|
+
.then(res => res.json())
|
|
987
|
+
.then(response => {
|
|
988
|
+
console.log("OmniFlow Sync: Successfully synced profile configuration to cloud server:", response);
|
|
989
|
+
})
|
|
990
|
+
.catch(err => {
|
|
991
|
+
console.error("OmniFlow Sync Error: Cloud server synchronization failed:", err);
|
|
992
|
+
});
|
|
993
|
+
*/
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Developer Hook: Download profile cloner backup package from cloud server to restore locally
|
|
998
|
+
* @param {string} profileId
|
|
999
|
+
*/
|
|
1000
|
+
function downloadProfileFromServer(profileId) {
|
|
1001
|
+
console.log("OmniFlow Developer Hook: downloadProfileFromServer triggered for ID:", profileId);
|
|
1002
|
+
|
|
1003
|
+
// Future implementation:
|
|
1004
|
+
/*
|
|
1005
|
+
const SERVER_API_ENDPOINT = `https://your-api.com/profiles/get?id=${profileId}`;
|
|
1006
|
+
fetch(SERVER_API_ENDPOINT, {
|
|
1007
|
+
method: "GET",
|
|
1008
|
+
headers: {
|
|
1009
|
+
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
|
|
1010
|
+
}
|
|
1011
|
+
})
|
|
1012
|
+
.then(res => res.json())
|
|
1013
|
+
.then(payload => {
|
|
1014
|
+
// Then call the exact same import sequence to inject settings & cookies!
|
|
1015
|
+
console.log("OmniFlow Sync: Successfully loaded profile data from cloud server.");
|
|
1016
|
+
})
|
|
1017
|
+
.catch(err => {
|
|
1018
|
+
console.error("OmniFlow Sync Error: Cloud download failed:", err);
|
|
1019
|
+
});
|
|
1020
|
+
*/
|
|
1021
|
+
}
|