-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
144 lines (129 loc) · 3.65 KB
/
Copy pathbackground.js
File metadata and controls
144 lines (129 loc) · 3.65 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// background.js : Service Worker centralisé pour XTool (Follow Réponses & Nettoyeur 0-Like)
// Initialisation des données au premier lancement ou mise à jour
chrome.runtime.onInstalled.addListener(async () => {
const data = await chrome.storage.local.get([
'followedAccounts',
'followerStats',
'followerSettings',
'settings',
'stats',
'logs',
'deletedIds'
]);
// Initialisation du module Follow Réponses
if (!data.followedAccounts) {
await chrome.storage.local.set({ followedAccounts: [] });
}
if (!data.followerStats) {
await chrome.storage.local.set({
followerStats: {
scannedReplies: 0,
newFollowed: 0,
alreadyFollowed: 0,
errors: 0
}
});
}
if (!data.followerSettings) {
await chrome.storage.local.set({
followerSettings: {
dryRun: false,
delayMin: 4000,
delayMax: 7000,
batchSize: 8,
batchPauseMin: 20000,
batchPauseMax: 35000,
limit: 30,
skipIfAlreadyFollowing: true,
onlyVerified: false
}
});
}
// Initialisation du module Nettoyeur 0-Like
if (!data.settings) {
await chrome.storage.local.set({
settings: {
dryRun: true,
limit: 50,
runnerMode: 'direct',
speedPreset: 'fast',
delayMin: 1200,
delayMax: 2200,
batchSize: 15,
batchPauseMin: 4000,
batchPauseMax: 7000
}
});
}
if (!data.stats) {
await chrome.storage.local.set({
stats: {
scanned: 0,
candidatesFound: 0,
deleted: 0,
dryRunDetected: 0,
savedLikes: 0,
errors: 0,
skippedRetweets: 0,
types: {
post: 0,
reply: 0,
quote: 0
}
}
});
}
if (!data.logs) {
await chrome.storage.local.set({ logs: [] });
}
if (!data.deletedIds) {
await chrome.storage.local.set({ deletedIds: [] });
}
});
// Écoute des messages en provenance du popup ou des content scripts
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
(async () => {
try {
if (message.type === 'UPDATE_BADGE') {
const { text, color } = message.payload || {};
if (text !== undefined) {
await chrome.action.setBadgeText({ text: String(text) });
}
if (color) {
await chrome.action.setBadgeBackgroundColor({ color });
}
sendResponse({ success: true });
return;
}
if (message.type === 'RATE_LIMIT_ALERT') {
await chrome.action.setBadgeText({ text: 'PAUSE' });
await chrome.action.setBadgeBackgroundColor({ color: '#ef4444' });
sendResponse({ success: true });
return;
}
if (message.type === 'CLEAR_RATE_LIMIT') {
await chrome.storage.local.set({
xRateLimitInfo: { isLimited: false, detectedAt: 0, resumeAt: 0, reason: '' }
});
await chrome.action.setBadgeText({ text: '' });
sendResponse({ success: true });
return;
}
if (message.type === 'CLEAR_BADGE') {
await chrome.action.setBadgeText({ text: '' });
sendResponse({ success: true });
return;
}
if (message.type === 'GET_ALL_DATA') {
const allData = await chrome.storage.local.get(null);
sendResponse({ success: true, data: allData });
return;
}
sendResponse({ success: true });
} catch (err) {
console.error('[XTool Background] Erreur traitement message:', err);
sendResponse({ success: false, error: err.message });
}
})();
return true; // Maintient le canal ouvert pour la réponse asynchrone
});