@onairosofficial/onairos-capacitor 0.1.4 → 0.1.5
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/OnairosofficialOnairosCapacitor.podspec +1 -1
- package/README.md +1 -1
- package/dist/onairos.capacitor.esm.js +509 -1
- package/dist/onairos.capacitor.esm.turbopack.js +509 -1
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosChatGPTNativePlugin.swift +187 -945
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosRNScrapers.swift +1800 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosSpotifyNativePlugin.swift +180 -629
- package/onairos.d.ts +24 -0
- package/package.json +5 -2
- package/src/assets/connectors/Linkedinicon.png +0 -0
- package/src/assets/connectors/Redditicon.png +0 -0
- package/src/assets/connectors/YouTubeicon2.png +0 -0
- package/src/assets/connectors/chatgpt.png +0 -0
- package/src/assets/connectors/claude.png +0 -0
- package/src/assets/connectors/instagram.png +0 -0
- package/src/assets/connectors/netflix.png +0 -0
- package/src/assets/connectors/pinterest.png +0 -0
- package/src/assets/connectors/sephora.png +0 -0
- package/src/assets/connectors/spotify.png +0 -0
- package/src/assets/connectors/tiktok.png +0 -0
- package/src/assets/permissions/onairos.png +0 -0
- package/src/assets/permissions/personalization.png +0 -0
- package/src/assets/permissions/public-profile-person.png +0 -0
- package/src/assets/permissions/raw-memories.png +0 -0
- package/src/capacitorConnectorCatalog.js +2 -6
- package/src/components/DataRequest.jsx +96 -532
- package/src/components/PinSetup.jsx +39 -226
- package/src/components/SDKDesignPreview.jsx +33 -0
- package/src/components/SessionUserBar.jsx +2 -1
- package/src/components/UniversalOnboarding.jsx +190 -423
- package/src/components/WelcomeScreen.jsx +7 -0
- package/src/components/parity/NativeConnections.jsx +136 -0
- package/src/components/parity/NativeScreens.jsx +48 -0
- package/src/components/ui/PageLayout.jsx +7 -3
- package/src/nativeImport/ConnectorLoading.jsx +13 -0
- package/src/nativeImport/CustomImportSession.js +115 -0
- package/src/nativeImport/ImportIcon.jsx +29 -0
- package/src/nativeImport/ImportProgress.jsx +24 -0
- package/src/nativeImport/ImportStatus.jsx +9 -0
- package/src/nativeImport/NativeChatImport.jsx +28 -0
- package/src/nativeImport/NativeImportSession.js +123 -0
- package/src/nativeImport/NativeScraperImport.jsx +57 -0
- package/src/nativeImport/SmartFilter.jsx +28 -0
- package/src/nativeImport/customPayload.js +37 -0
- package/src/nativeImport/netflixExport.js +30 -0
- package/src/nativeImport/netflixHistory.js +28 -0
- package/src/nativeImport/netflixSession.js +59 -0
- package/src/nativeImport/rawHandoff.js +7 -0
- package/src/nativeImport/rn/config/api.js +5 -0
- package/src/nativeImport/rn/services/apiKeyService.js +2 -0
- package/src/nativeImport/rn/services/hingePayload.js +37 -0
- package/src/nativeImport/rn/services/nativeConversationImport.js +138 -0
- package/src/nativeImport/rn/services/nativeFileTransfer.js +127 -0
- package/src/nativeImport/rn/services/nativeRawRedaction.js +136 -0
- package/src/nativeImport/rn/services/netflixPayload.js +70 -0
- package/src/nativeImport/rn/services/rawMemoryPolicy.js +38 -0
- package/src/nativeImport/rn/services/sephoraPayload.js +166 -0
- package/src/nativeImport/rn/services/spotifyPayload.js +99 -0
- package/src/nativeImport/rn/source-manifest.json +45 -0
- package/src/nativeImport/rn/utils/importedFiles.js +74 -0
- package/src/nativeImport/rn/utils/nativeImportDates.js +45 -0
- package/src/nativeImport/rn/utils/nativeImportFileReceiver.js +51 -0
- package/src/nativeImport/rn/utils/nativeImportMetadata.js +74 -0
- package/src/nativeImport/rn/utils/nativeImportTopics.js +56 -0
- package/src/nativeImport/rn/utils/rawExportDelivery.js +12 -0
- package/src/nativeImport/rn/utils/webviewScripts/chatgptDiscovery.js +99 -0
- package/src/nativeImport/rn/utils/webviewScripts/claude.js +349 -0
- package/src/nativeImport/rn/utils/webviewScripts/gemini.js +356 -0
- package/src/nativeImport/rn/utils/webviewScripts/hinge.js +375 -0
- package/src/nativeImport/rn/utils/webviewScripts/instagram.js +152 -0
- package/src/nativeImport/rn/utils/webviewScripts/linkedin.js +825 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeChatGPTImport.js +202 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeChatGPTSession.js +63 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeImportFiles.js +132 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeImportProviders.js +80 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeLoginViewport.js +28 -0
- package/src/nativeImport/rn/utils/webviewScripts/netflix.js +257 -0
- package/src/nativeImport/rn/utils/webviewScripts/sephora.js +862 -0
- package/src/nativeImport/rn/utils/webviewScripts/sephoraSession.js +160 -0
- package/src/nativeImport/rn/utils/webviewScripts/spotify.js +1868 -0
- package/src/nativeImport/rn/utils/webviewScripts/telegram.js +630 -0
- package/src/nativeImport/rn/utils/webviewScripts/tiktok.js +2920 -0
- package/src/onairos.core.jsx +3 -0
- package/src/onairosButton.jsx +23 -17
- package/src/styles/onairos-rn-parity.css +175 -0
- package/src/styles/tailwind.capacitor.css +4 -0
- package/src/utils/nativeConnectorSession.js +18 -0
- package/src/utils/parityPolicy.js +41 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
// Synced from RN utils/webviewScripts/telegram.ts by scripts/sync-rn-connectors.cjs.
|
|
2
|
+
const TELEGRAM_CONSENT_POPUP_SCRIPT = `
|
|
3
|
+
(function() {
|
|
4
|
+
try {
|
|
5
|
+
const existing = document.getElementById('onairos-consent-overlay');
|
|
6
|
+
if (existing) existing.remove();
|
|
7
|
+
|
|
8
|
+
const overlay = document.createElement('div');
|
|
9
|
+
overlay.id = 'onairos-consent-overlay';
|
|
10
|
+
overlay.style.cssText = \`
|
|
11
|
+
position: fixed;
|
|
12
|
+
top: 0;
|
|
13
|
+
left: 0;
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 100%;
|
|
16
|
+
background: rgba(0, 0, 0, 0.7);
|
|
17
|
+
z-index: 999999;
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
22
|
+
\`;
|
|
23
|
+
|
|
24
|
+
const popup = document.createElement('div');
|
|
25
|
+
popup.style.cssText = \`
|
|
26
|
+
background: white;
|
|
27
|
+
border-radius: 16px;
|
|
28
|
+
padding: 32px;
|
|
29
|
+
max-width: 400px;
|
|
30
|
+
width: 90%;
|
|
31
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
32
|
+
\`;
|
|
33
|
+
|
|
34
|
+
popup.innerHTML = \`
|
|
35
|
+
<div style="text-align: center;">
|
|
36
|
+
<div style="font-size: 48px; margin-bottom: 16px;">\u2708\uFE0F</div>
|
|
37
|
+
<h2 style="margin: 0 0 12px 0; font-size: 24px; color: #1a1a1a;">
|
|
38
|
+
Export Telegram Data?
|
|
39
|
+
</h2>
|
|
40
|
+
<p style="margin: 0 0 24px 0; color: #666; font-size: 16px; line-height: 1.5;">
|
|
41
|
+
Allow Onairos to export your recent Telegram messages for analysis?
|
|
42
|
+
</p>
|
|
43
|
+
<div style="display: flex; gap: 12px; justify-content: center;">
|
|
44
|
+
<button id="onairos-deny" style="
|
|
45
|
+
flex: 1;
|
|
46
|
+
padding: 14px 24px;
|
|
47
|
+
border: 2px solid #e0e0e0;
|
|
48
|
+
background: white;
|
|
49
|
+
color: #666;
|
|
50
|
+
border-radius: 8px;
|
|
51
|
+
font-size: 16px;
|
|
52
|
+
font-weight: 600;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
">Deny</button>
|
|
55
|
+
<button id="onairos-allow" style="
|
|
56
|
+
flex: 1;
|
|
57
|
+
padding: 14px 24px;
|
|
58
|
+
border: none;
|
|
59
|
+
background: linear-gradient(135deg, #0088CC 0%, #0066AA 100%);
|
|
60
|
+
color: white;
|
|
61
|
+
border-radius: 8px;
|
|
62
|
+
font-size: 16px;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
">Allow</button>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
\`;
|
|
69
|
+
|
|
70
|
+
overlay.appendChild(popup);
|
|
71
|
+
document.body.appendChild(overlay);
|
|
72
|
+
|
|
73
|
+
document.getElementById('onairos-deny').onclick = () => {
|
|
74
|
+
overlay.remove();
|
|
75
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
76
|
+
type: 'TELEGRAM_CONSENT',
|
|
77
|
+
status: 'denied'
|
|
78
|
+
}));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
document.getElementById('onairos-allow').onclick = () => {
|
|
82
|
+
document.getElementById('onairos-allow').innerHTML = '\u23F3 Starting...';
|
|
83
|
+
document.getElementById('onairos-allow').disabled = true;
|
|
84
|
+
|
|
85
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
86
|
+
type: 'TELEGRAM_CONSENT',
|
|
87
|
+
status: 'allowed'
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
setTimeout(() => overlay.remove(), 500);
|
|
91
|
+
};
|
|
92
|
+
} catch (error) {
|
|
93
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
94
|
+
type: 'TELEGRAM_CONSENT',
|
|
95
|
+
status: 'error',
|
|
96
|
+
message: error.message
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
true;
|
|
101
|
+
`;
|
|
102
|
+
const TELEGRAM_EXPORT_SCRIPT = `
|
|
103
|
+
(function() {
|
|
104
|
+
try {
|
|
105
|
+
console.log('\u{1F504} [TELEGRAM] Script version: SDK_V2_MTPROTO');
|
|
106
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
107
|
+
type: 'DEBUG_LOG',
|
|
108
|
+
message: 'Telegram Script version: SDK_V2_MTPROTO loaded'
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
if (!document.body) {
|
|
112
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
113
|
+
type: 'TELEGRAM_EXPORT_ERROR',
|
|
114
|
+
message: 'Page not ready'
|
|
115
|
+
}));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ============================================================
|
|
120
|
+
// TELEGRAM WEB EXTRACTION CONFIG
|
|
121
|
+
// Based on MTProto API Layer 214+
|
|
122
|
+
// ============================================================
|
|
123
|
+
const TELEGRAM_CONFIG = {
|
|
124
|
+
// Telegram Web URLs
|
|
125
|
+
webUrl: 'https://web.telegram.org',
|
|
126
|
+
|
|
127
|
+
// IndexedDB database names used by different Telegram Web versions
|
|
128
|
+
// These databases cache MTProto API responses
|
|
129
|
+
indexedDBConfig: {
|
|
130
|
+
// Telegram Web K (most common, what web.telegram.org/k/ uses)
|
|
131
|
+
k: {
|
|
132
|
+
dbName: 'tweb',
|
|
133
|
+
stores: {
|
|
134
|
+
dialogs: 'dialogs', // From messages.getDialogs
|
|
135
|
+
messages: 'messages', // From messages.getHistory
|
|
136
|
+
users: 'users', // User entities
|
|
137
|
+
chats: 'chats', // Chat/Channel entities
|
|
138
|
+
peers: 'peers', // Peer mappings
|
|
139
|
+
session: 'session', // Auth session
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
// Telegram Web A (React version)
|
|
143
|
+
a: {
|
|
144
|
+
dbName: 'telegram-t',
|
|
145
|
+
stores: {
|
|
146
|
+
chats: 'chats',
|
|
147
|
+
messages: 'messages',
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
// Alternative storage (keyval)
|
|
151
|
+
keyval: {
|
|
152
|
+
dbName: 'keyval-store',
|
|
153
|
+
stores: {}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
// MTProto entity types (from API)
|
|
158
|
+
entityTypes: {
|
|
159
|
+
User: 'User',
|
|
160
|
+
Chat: 'Chat', // Basic group
|
|
161
|
+
Channel: 'Channel', // Channel or Supergroup
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
// Check if user is logged in
|
|
165
|
+
// Telegram Web stores auth keys in localStorage
|
|
166
|
+
isLoggedIn: () => {
|
|
167
|
+
// DC auth keys (MTProto data centers)
|
|
168
|
+
const dc2AuthKey = localStorage.getItem('dc2_auth_key');
|
|
169
|
+
const userAuth = localStorage.getItem('user_auth');
|
|
170
|
+
|
|
171
|
+
// Alternative: check for session in IndexedDB
|
|
172
|
+
// Or check DOM for chat list presence
|
|
173
|
+
const hasChats = document.querySelector('[class*="chat-list"]') ||
|
|
174
|
+
document.querySelector('[class*="ChatList"]') ||
|
|
175
|
+
document.querySelector('.dialogs-container') ||
|
|
176
|
+
document.querySelector('[class*="LeftColumn"]');
|
|
177
|
+
|
|
178
|
+
return !!(dc2AuthKey || userAuth || hasChats);
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
// Extract user ID from cached auth data
|
|
182
|
+
getUserId: () => {
|
|
183
|
+
try {
|
|
184
|
+
// Primary: user_auth localStorage key
|
|
185
|
+
const userAuth = localStorage.getItem('user_auth');
|
|
186
|
+
if (userAuth) {
|
|
187
|
+
const parsed = JSON.parse(userAuth);
|
|
188
|
+
return parsed.id || parsed.user_id;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Fallback: Check dc_auth_* pattern
|
|
192
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
193
|
+
const key = localStorage.key(i);
|
|
194
|
+
if (key && key.includes('user')) {
|
|
195
|
+
try {
|
|
196
|
+
const val = JSON.parse(localStorage.getItem(key));
|
|
197
|
+
if (val && val.id) return val.id;
|
|
198
|
+
} catch (e) {}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Mini App context (if opened as webapp)
|
|
203
|
+
if (window.Telegram && window.Telegram.WebApp) {
|
|
204
|
+
return window.Telegram.WebApp.initDataUnsafe?.user?.id;
|
|
205
|
+
}
|
|
206
|
+
} catch (e) {
|
|
207
|
+
console.log('[TELEGRAM] Could not extract user ID:', e.message);
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
// ============================================================
|
|
213
|
+
|
|
214
|
+
console.log('\u{1F680} [TELEGRAM] Starting MTProto data extraction...');
|
|
215
|
+
|
|
216
|
+
(async () => {
|
|
217
|
+
try {
|
|
218
|
+
// STEP 1: Check login status
|
|
219
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
220
|
+
type: 'TELEGRAM_EXPORT_PROGRESS',
|
|
221
|
+
stage: 'checking_auth',
|
|
222
|
+
progress: 5,
|
|
223
|
+
message: 'Checking MTProto authentication...'
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
const isLoggedIn = TELEGRAM_CONFIG.isLoggedIn();
|
|
227
|
+
console.log('[TELEGRAM] Logged in:', isLoggedIn);
|
|
228
|
+
|
|
229
|
+
if (!isLoggedIn) {
|
|
230
|
+
throw new Error('User not logged in to Telegram Web. Please log in first.');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const userId = TELEGRAM_CONFIG.getUserId();
|
|
234
|
+
console.log('[TELEGRAM] User ID:', userId);
|
|
235
|
+
|
|
236
|
+
// STEP 2: Read from IndexedDB (cached MTProto responses)
|
|
237
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
238
|
+
type: 'TELEGRAM_EXPORT_PROGRESS',
|
|
239
|
+
stage: 'fetching_dialogs',
|
|
240
|
+
progress: 15,
|
|
241
|
+
message: 'Reading dialogs from cache (messages.getDialogs)...'
|
|
242
|
+
}));
|
|
243
|
+
|
|
244
|
+
let dialogs = [];
|
|
245
|
+
let messages = [];
|
|
246
|
+
let users = [];
|
|
247
|
+
let chats = [];
|
|
248
|
+
|
|
249
|
+
// Try to read from IndexedDB - Telegram Web caches MTProto responses here
|
|
250
|
+
console.log('[TELEGRAM] Reading IndexedDB cache...');
|
|
251
|
+
|
|
252
|
+
const dbConfigs = [
|
|
253
|
+
TELEGRAM_CONFIG.indexedDBConfig.k,
|
|
254
|
+
TELEGRAM_CONFIG.indexedDBConfig.a,
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
for (const dbConfig of dbConfigs) {
|
|
258
|
+
if (dialogs.length > 0) break;
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const dbRequest = indexedDB.open(dbConfig.dbName);
|
|
262
|
+
|
|
263
|
+
await new Promise((resolve, reject) => {
|
|
264
|
+
dbRequest.onerror = () => {
|
|
265
|
+
console.log('[TELEGRAM] Cannot open DB:', dbConfig.dbName);
|
|
266
|
+
resolve();
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
dbRequest.onsuccess = async () => {
|
|
270
|
+
const db = dbRequest.result;
|
|
271
|
+
const storeNames = [...db.objectStoreNames];
|
|
272
|
+
console.log('[TELEGRAM] Opened DB:', dbConfig.dbName, 'Stores:', storeNames);
|
|
273
|
+
|
|
274
|
+
// Read dialogs (from messages.getDialogs cache)
|
|
275
|
+
if (storeNames.includes('dialogs') || storeNames.includes('chats')) {
|
|
276
|
+
const storeName = storeNames.includes('dialogs') ? 'dialogs' : 'chats';
|
|
277
|
+
try {
|
|
278
|
+
const tx = db.transaction(storeName, 'readonly');
|
|
279
|
+
const store = tx.objectStore(storeName);
|
|
280
|
+
const getAllReq = store.getAll();
|
|
281
|
+
|
|
282
|
+
await new Promise((res, rej) => {
|
|
283
|
+
getAllReq.onsuccess = () => {
|
|
284
|
+
dialogs = getAllReq.result || [];
|
|
285
|
+
console.log('[TELEGRAM] Found', dialogs.length, 'dialogs in', storeName);
|
|
286
|
+
res();
|
|
287
|
+
};
|
|
288
|
+
getAllReq.onerror = () => res();
|
|
289
|
+
});
|
|
290
|
+
} catch (e) {
|
|
291
|
+
console.log('[TELEGRAM] Error reading dialogs:', e.message);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Read messages (from messages.getHistory cache)
|
|
296
|
+
if (storeNames.includes('messages')) {
|
|
297
|
+
try {
|
|
298
|
+
const tx = db.transaction('messages', 'readonly');
|
|
299
|
+
const store = tx.objectStore('messages');
|
|
300
|
+
const getAllReq = store.getAll();
|
|
301
|
+
|
|
302
|
+
await new Promise((res, rej) => {
|
|
303
|
+
getAllReq.onsuccess = () => {
|
|
304
|
+
messages = getAllReq.result || [];
|
|
305
|
+
console.log('[TELEGRAM] Found', messages.length, 'messages');
|
|
306
|
+
res();
|
|
307
|
+
};
|
|
308
|
+
getAllReq.onerror = () => res();
|
|
309
|
+
});
|
|
310
|
+
} catch (e) {
|
|
311
|
+
console.log('[TELEGRAM] Error reading messages:', e.message);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Read users (entity cache)
|
|
316
|
+
if (storeNames.includes('users')) {
|
|
317
|
+
try {
|
|
318
|
+
const tx = db.transaction('users', 'readonly');
|
|
319
|
+
const store = tx.objectStore('users');
|
|
320
|
+
const getAllReq = store.getAll();
|
|
321
|
+
|
|
322
|
+
await new Promise((res, rej) => {
|
|
323
|
+
getAllReq.onsuccess = () => {
|
|
324
|
+
users = getAllReq.result || [];
|
|
325
|
+
console.log('[TELEGRAM] Found', users.length, 'users');
|
|
326
|
+
res();
|
|
327
|
+
};
|
|
328
|
+
getAllReq.onerror = () => res();
|
|
329
|
+
});
|
|
330
|
+
} catch (e) {}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Read chats/channels (entity cache)
|
|
334
|
+
if (storeNames.includes('chats') && storeNames.includes('dialogs')) {
|
|
335
|
+
try {
|
|
336
|
+
const tx = db.transaction('chats', 'readonly');
|
|
337
|
+
const store = tx.objectStore('chats');
|
|
338
|
+
const getAllReq = store.getAll();
|
|
339
|
+
|
|
340
|
+
await new Promise((res, rej) => {
|
|
341
|
+
getAllReq.onsuccess = () => {
|
|
342
|
+
chats = getAllReq.result || [];
|
|
343
|
+
console.log('[TELEGRAM] Found', chats.length, 'chats/channels');
|
|
344
|
+
res();
|
|
345
|
+
};
|
|
346
|
+
getAllReq.onerror = () => res();
|
|
347
|
+
});
|
|
348
|
+
} catch (e) {}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
db.close();
|
|
352
|
+
resolve();
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
} catch (dbError) {
|
|
357
|
+
console.log('[TELEGRAM] DB error:', dbConfig.dbName, dbError.message);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Fallback: Scrape from DOM if IndexedDB didn't work
|
|
362
|
+
if (dialogs.length === 0) {
|
|
363
|
+
console.log('[TELEGRAM] IndexedDB empty, falling back to DOM scraping...');
|
|
364
|
+
|
|
365
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
366
|
+
type: 'TELEGRAM_EXPORT_PROGRESS',
|
|
367
|
+
stage: 'scraping_dom',
|
|
368
|
+
progress: 30,
|
|
369
|
+
message: 'Reading visible chats from UI...'
|
|
370
|
+
}));
|
|
371
|
+
|
|
372
|
+
// Extract chat list from DOM (matches Telegram Web K structure)
|
|
373
|
+
const chatElements = document.querySelectorAll(
|
|
374
|
+
'[data-peer-id], ' +
|
|
375
|
+
'.chatlist-chat, ' +
|
|
376
|
+
'[class*="ListItem"][class*="Chat"], ' +
|
|
377
|
+
'.Dialog, ' +
|
|
378
|
+
'[class*="chat-list"] > div'
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
chatElements.forEach((el, idx) => {
|
|
382
|
+
const peerId = el.getAttribute('data-peer-id');
|
|
383
|
+
const titleEl = el.querySelector(
|
|
384
|
+
'.peer-title, ' +
|
|
385
|
+
'[class*="title"]:not([class*="subtitle"]), ' +
|
|
386
|
+
'.name, ' +
|
|
387
|
+
'[class*="ListItem-title"]'
|
|
388
|
+
);
|
|
389
|
+
const lastMsgEl = el.querySelector(
|
|
390
|
+
'.last-message, ' +
|
|
391
|
+
'[class*="subtitle"], ' +
|
|
392
|
+
'[class*="LastMessage"]'
|
|
393
|
+
);
|
|
394
|
+
const unreadBadge = el.querySelector(
|
|
395
|
+
'.unread-count, ' +
|
|
396
|
+
'[class*="badge"], ' +
|
|
397
|
+
'[class*="unread"]'
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
if (titleEl) {
|
|
401
|
+
const unreadCount = unreadBadge ? parseInt(unreadBadge.textContent) || 0 : 0;
|
|
402
|
+
|
|
403
|
+
dialogs.push({
|
|
404
|
+
id: peerId || 'chat-' + idx,
|
|
405
|
+
title: titleEl.textContent?.trim() || 'Unknown Chat',
|
|
406
|
+
lastMessage: lastMsgEl?.textContent?.trim() || '',
|
|
407
|
+
type: 'Chat', // MTProto entity type
|
|
408
|
+
unreadCount: unreadCount,
|
|
409
|
+
pinned: el.classList.contains('pinned') || el.hasAttribute('data-pinned'),
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
console.log('[TELEGRAM] Scraped', dialogs.length, 'dialogs from DOM');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// STEP 3: Extract messages from visible chat (if any chat is open)
|
|
418
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
419
|
+
type: 'TELEGRAM_EXPORT_PROGRESS',
|
|
420
|
+
stage: 'extracting_messages',
|
|
421
|
+
progress: 50,
|
|
422
|
+
message: 'Extracting messages (messages.getHistory)...'
|
|
423
|
+
}));
|
|
424
|
+
|
|
425
|
+
if (messages.length === 0) {
|
|
426
|
+
// Scrape messages from currently open chat
|
|
427
|
+
const messageElements = document.querySelectorAll(
|
|
428
|
+
'[data-message-id], ' +
|
|
429
|
+
'.message, ' +
|
|
430
|
+
'.bubble, ' +
|
|
431
|
+
'[class*="Message"]:not([class*="MessageList"])'
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
messageElements.forEach((el, idx) => {
|
|
435
|
+
const msgId = el.getAttribute('data-message-id') ||
|
|
436
|
+
el.getAttribute('data-mid') ||
|
|
437
|
+
'msg-' + idx;
|
|
438
|
+
|
|
439
|
+
// Check if outgoing (user's message)
|
|
440
|
+
const isOutgoing = el.classList.contains('out') ||
|
|
441
|
+
el.classList.contains('is-out') ||
|
|
442
|
+
el.getAttribute('data-is-out') === 'true' ||
|
|
443
|
+
el.closest('.bubbles-group-out') !== null;
|
|
444
|
+
|
|
445
|
+
const textEl = el.querySelector(
|
|
446
|
+
'.text-content, ' +
|
|
447
|
+
'.message-content, ' +
|
|
448
|
+
'[class*="text-entity"], ' +
|
|
449
|
+
'.translatable-message'
|
|
450
|
+
);
|
|
451
|
+
const timeEl = el.querySelector(
|
|
452
|
+
'.time, ' +
|
|
453
|
+
'.time-inner, ' +
|
|
454
|
+
'[class*="MessageMeta"] time, ' +
|
|
455
|
+
'.message-time'
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
// Get message text
|
|
459
|
+
const text = textEl?.textContent?.trim() || '';
|
|
460
|
+
|
|
461
|
+
// Only extract outgoing messages (user's own messages)
|
|
462
|
+
if (text && isOutgoing) {
|
|
463
|
+
// Try to extract Unix timestamp
|
|
464
|
+
let timestamp = null;
|
|
465
|
+
if (timeEl) {
|
|
466
|
+
const timeAttr = timeEl.getAttribute('datetime') ||
|
|
467
|
+
timeEl.getAttribute('data-timestamp');
|
|
468
|
+
if (timeAttr) {
|
|
469
|
+
timestamp = new Date(timeAttr).getTime() / 1000; // Unix timestamp
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
messages.push({
|
|
474
|
+
id: msgId,
|
|
475
|
+
text: text,
|
|
476
|
+
timestamp: timestamp || timeEl?.textContent?.trim() || '',
|
|
477
|
+
date: timestamp, // MTProto uses 'date' field
|
|
478
|
+
out: true, // MTProto uses 'out' boolean
|
|
479
|
+
type: 'text',
|
|
480
|
+
fromId: userId,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
console.log('[TELEGRAM] Scraped', messages.length, 'outgoing messages from DOM');
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// STEP 4: Process and format data to match MTProto structure
|
|
489
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
490
|
+
type: 'TELEGRAM_EXPORT_PROGRESS',
|
|
491
|
+
stage: 'processing',
|
|
492
|
+
progress: 75,
|
|
493
|
+
message: 'Processing MTProto data...'
|
|
494
|
+
}));
|
|
495
|
+
|
|
496
|
+
// Format dialogs to match messages.Dialogs structure
|
|
497
|
+
const formattedDialogs = dialogs.slice(0, 100).map((dialog, idx) => {
|
|
498
|
+
// Determine entity type (User, Chat, Channel)
|
|
499
|
+
let type = dialog._ || dialog.type || 'Chat';
|
|
500
|
+
if (dialog.megagroup || dialog.broadcast) {
|
|
501
|
+
type = 'Channel';
|
|
502
|
+
} else if (dialog.first_name || dialog.last_name) {
|
|
503
|
+
type = 'User';
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return {
|
|
507
|
+
// Dialog fields (from messages.getDialogs)
|
|
508
|
+
id: dialog.id || dialog.peerId || dialog.peer?.user_id || dialog.peer?.chat_id || dialog.peer?.channel_id,
|
|
509
|
+
title: dialog.title || dialog.name ||
|
|
510
|
+
(dialog.first_name ? (dialog.first_name + ' ' + (dialog.last_name || '')).trim() : 'Unknown'),
|
|
511
|
+
type: type,
|
|
512
|
+
|
|
513
|
+
// Dialog metadata
|
|
514
|
+
unreadCount: dialog.unread_count || dialog.unreadCount || 0,
|
|
515
|
+
pinned: dialog.pinned || false,
|
|
516
|
+
folderId: dialog.folder_id || 0, // 0=main, 1=archived
|
|
517
|
+
topMessageId: dialog.top_message,
|
|
518
|
+
readInboxMaxId: dialog.read_inbox_max_id,
|
|
519
|
+
readOutboxMaxId: dialog.read_outbox_max_id,
|
|
520
|
+
|
|
521
|
+
// Last message date (Unix timestamp)
|
|
522
|
+
lastMessageDate: dialog.date || dialog.lastMessageDate,
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// Format messages to match messages.Messages structure
|
|
527
|
+
const userMessages = messages
|
|
528
|
+
.filter(msg => msg.out || msg.isOutgoing || msg.fromId === userId)
|
|
529
|
+
.slice(0, 500)
|
|
530
|
+
.map(msg => ({
|
|
531
|
+
// Message fields (from messages.getHistory)
|
|
532
|
+
id: msg.id || msg.mid,
|
|
533
|
+
chatId: msg.peer_id || msg.peerId || msg.chatId,
|
|
534
|
+
text: msg.message || msg.text || '',
|
|
535
|
+
|
|
536
|
+
// MTProto timestamp (Unix)
|
|
537
|
+
date: msg.date || Math.floor(new Date(msg.timestamp).getTime() / 1000),
|
|
538
|
+
timestamp: msg.date || msg.timestamp,
|
|
539
|
+
|
|
540
|
+
// Message metadata
|
|
541
|
+
type: msg.media ? (msg.media._ || 'media') : 'text',
|
|
542
|
+
fromId: msg.from_id || msg.fromId || userId,
|
|
543
|
+
out: true, // These are all outgoing
|
|
544
|
+
|
|
545
|
+
// Reply info
|
|
546
|
+
replyToMsgId: msg.reply_to?.reply_to_msg_id,
|
|
547
|
+
}));
|
|
548
|
+
|
|
549
|
+
console.log('\u2705 [TELEGRAM] MTProto extraction complete:', {
|
|
550
|
+
dialogs: formattedDialogs.length,
|
|
551
|
+
messages: userMessages.length,
|
|
552
|
+
users: users.length,
|
|
553
|
+
chats: chats.length,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
// STEP 5: Send results (matching messages.Dialogs + messages.Messages structure)
|
|
557
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
558
|
+
type: 'TELEGRAM_EXPORT_COMPLETE',
|
|
559
|
+
status: 'success',
|
|
560
|
+
data: {
|
|
561
|
+
// Main data (from messages.getDialogs + messages.getHistory)
|
|
562
|
+
dialogs: formattedDialogs,
|
|
563
|
+
messages: userMessages,
|
|
564
|
+
|
|
565
|
+
// Entity caches (users/chats referenced in dialogs/messages)
|
|
566
|
+
users: users.slice(0, 100).map(u => ({
|
|
567
|
+
id: u.id,
|
|
568
|
+
firstName: u.first_name,
|
|
569
|
+
lastName: u.last_name,
|
|
570
|
+
username: u.username,
|
|
571
|
+
})),
|
|
572
|
+
chats: chats.slice(0, 100).map(c => ({
|
|
573
|
+
id: c.id,
|
|
574
|
+
title: c.title,
|
|
575
|
+
type: c._ || c.type,
|
|
576
|
+
})),
|
|
577
|
+
|
|
578
|
+
// Summary
|
|
579
|
+
summary: {
|
|
580
|
+
dialogCount: formattedDialogs.length,
|
|
581
|
+
messageCount: userMessages.length,
|
|
582
|
+
},
|
|
583
|
+
|
|
584
|
+
// User info
|
|
585
|
+
userId: userId,
|
|
586
|
+
},
|
|
587
|
+
success: true
|
|
588
|
+
}));
|
|
589
|
+
|
|
590
|
+
} catch (error) {
|
|
591
|
+
console.error('\u274C [TELEGRAM] Export failed:', error.message);
|
|
592
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
593
|
+
type: 'TELEGRAM_EXPORT_ERROR',
|
|
594
|
+
status: 'error',
|
|
595
|
+
message: 'MTProto extraction failed: ' + error.message,
|
|
596
|
+
success: false
|
|
597
|
+
}));
|
|
598
|
+
}
|
|
599
|
+
})();
|
|
600
|
+
|
|
601
|
+
} catch (error) {
|
|
602
|
+
console.error('\u274C [TELEGRAM] Init error:', error.message);
|
|
603
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
604
|
+
type: 'TELEGRAM_EXPORT_ERROR',
|
|
605
|
+
status: 'error',
|
|
606
|
+
message: 'Script initialization error: ' + error.message,
|
|
607
|
+
success: false
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
})();
|
|
611
|
+
true;
|
|
612
|
+
`;
|
|
613
|
+
const TELEGRAM_SUCCESS_SCRIPT = `
|
|
614
|
+
(function() {
|
|
615
|
+
console.log('\u2705 Telegram export successful!');
|
|
616
|
+
})();
|
|
617
|
+
true;
|
|
618
|
+
`;
|
|
619
|
+
const TELEGRAM_ERROR_SCRIPT = `
|
|
620
|
+
(function() {
|
|
621
|
+
console.log('\u274C Telegram export failed!');
|
|
622
|
+
})();
|
|
623
|
+
true;
|
|
624
|
+
`;
|
|
625
|
+
export {
|
|
626
|
+
TELEGRAM_CONSENT_POPUP_SCRIPT,
|
|
627
|
+
TELEGRAM_ERROR_SCRIPT,
|
|
628
|
+
TELEGRAM_EXPORT_SCRIPT,
|
|
629
|
+
TELEGRAM_SUCCESS_SCRIPT
|
|
630
|
+
};
|