Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
70 lines (63 loc) · 2.78 KB
/
Copy pathbackground.js
File metadata and controls
70 lines (63 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let downloadCounter = 0;
function downloadWithRetry(options, retriesLeft) {
try {
chrome.downloads.download(options, (downloadId) => {
if (chrome.runtime.lastError) {
console.error('[Tinder Extractor] Download failed for ' + options.filename + ':', chrome.runtime.lastError.message);
if (retriesLeft > 0) {
console.log(`[Tinder Extractor] Retrying ${options.filename}... (${retriesLeft} retries left)`);
setTimeout(() => downloadWithRetry(options, retriesLeft - 1), 2000);
}
}
});
} catch (e) {
console.error('[Tinder Extractor] Exception triggering download:', e);
}
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'downloadData') {
const userData = message.data;
const basePath = message.path || 'Tinder Data';
const username = userData.name ? userData.name.replace(/[^a-zA-Z0-9]/g, '_') + '_' + userData._id : userData._id;
// 1. Download JSON data
setTimeout(() => {
try {
const jsonString = JSON.stringify(userData, null, 2);
const jsonBlob = new Blob([jsonString], { type: 'application/json' });
const jsonUrl = URL.createObjectURL(jsonBlob);
downloadWithRetry({
url: jsonUrl,
filename: `${basePath}/${username}/${username}.json`,
saveAs: false,
conflictAction: 'overwrite'
}, 2); // 2 retries
} catch (e) {
console.error('[Tinder Extractor] Error creating JSON blob:', e);
}
}, downloadCounter * 50); // Faster stagger
downloadCounter++;
// 2. Download Photos
if (userData.photos && Array.isArray(userData.photos)) {
userData.photos.forEach((photo, index) => {
if (photo.url) {
let ext = 'jpg';
const match = photo.url.match(/\.([a-zA-Z0-9]+)(?:[\?#]|$)/);
if (match) ext = match[1];
setTimeout(() => {
downloadWithRetry({
url: photo.url,
filename: `${basePath}/${username}/images/photo_${index + 1}.${ext}`,
saveAs: false,
conflictAction: 'overwrite'
}, 2); // 2 retries
}, downloadCounter * 50); // Faster stagger
downloadCounter++;
}
});
}
// Reset counter periodically
setTimeout(() => {
downloadCounter = 0;
}, 1500);
}
});