-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
59 lines (50 loc) · 1.84 KB
/
background.js
File metadata and controls
59 lines (50 loc) · 1.84 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
// content script로부터 메시지 수신 처리
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'SOCIAL_LOGIN_DETECTED') {
storeSocialLogin(message.data);
}
});
// 소셜 로그인 정보를 Chrome Storage에 저장하는 함수
async function storeSocialLogin(data) {
try {
const { site, provider, providerName, timestamp, url } = data;
// 기존 저장된 소셜 로그인 데이터 가져오기
const result = await chrome.storage.local.get('socialLogins');
const socialLogins = result.socialLogins || {};
// 사이트별 배열 초기화
if (!socialLogins[site]) {
socialLogins[site] = [];
}
// 동일한 제공업체로 기존 로그인이 있는지 확인
const existingLogin = socialLogins[site].find(login => login.provider === provider);
// 기존 기록이 있으면 업데이트, 없으면 새로 추가
if (existingLogin) {
existingLogin.lastUsed = timestamp;
existingLogin.count = (existingLogin.count || 1) + 1;
} else {
socialLogins[site].push({
provider,
providerName,
firstUsed: timestamp,
lastUsed: timestamp,
count: 1,
url
});
}
// 업데이트된 데이터를 저장
await chrome.storage.local.set({ socialLogins });
console.log(`Stored social login: ${providerName} for ${site}`);
} catch (error) {
console.error('Error storing social login:', error);
}
}
// 확장프로그램 아이콘 클릭 시 팝업 열기
chrome.action.onClicked.addListener((tab) => {
chrome.action.openPopup();
});
// Storage 변경사항 모니터링 (디버깅용)
chrome.storage.onChanged.addListener((changes, namespace) => {
if (changes.socialLogins) {
console.log('Social logins updated:', changes.socialLogins.newValue);
}
});