-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
76 lines (65 loc) · 2.22 KB
/
background.js
File metadata and controls
76 lines (65 loc) · 2.22 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
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
console.log('FunPay Golden Key Manager установлен');
// Инициализация хранилища
chrome.storage.local.set({
accounts: []
});
}
});
chrome.action.onClicked.addListener((tab) => {
});
function log(message, data = null) {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] ${message}`, data || '');
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getGoldenKey') {
chrome.cookies.get({
url: request.url || 'https://funpay.com',
name: 'golden_key'
}, (cookie) => {
sendResponse({ key: cookie?.value || null });
});
return true; // Асинхронный ответ
}
if (request.action === 'setGoldenKey') {
const domains = [
'https://funpay.com',
'https://funpay.ru',
'https://www.funpay.com',
'https://www.funpay.ru'
];
Promise.all(domains.map(domain =>
chrome.cookies.set({
url: domain,
name: 'golden_key',
value: request.key,
path: '/',
secure: true,
sameSite: 'lax'
})
)).then(() => {
log('Golden key установлен для всех доменов');
sendResponse({ success: true });
}).catch(error => {
log('Ошибка установки golden key', error);
sendResponse({ success: false, error: error.message });
});
return true;
}
if (request.action === 'log') {
log(request.message, request.data);
sendResponse({ success: true });
}
});
chrome.cookies.onChanged.addListener((changeInfo) => {
if (changeInfo.cookie.name === 'golden_key') {
if (changeInfo.removed) {
log('Golden key был удалён');
} else {
log('Golden key был изменён');
}
}
});
log('FunPay Golden Key Manager background service запущен');