-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpopup.js
More file actions
51 lines (43 loc) · 2.02 KB
/
popup.js
File metadata and controls
51 lines (43 loc) · 2.02 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
// popup.js - 팝업 창의 슬라이더 동작과 다국어 처리
document.addEventListener('DOMContentLoaded', function() {
const slider = document.getElementById('widthSlider'); // popup.html의 슬라이더 ID와 일치해야 함
const checkbox = document.getElementById('cleanView');
// ---- I18N: set popup text ----
const titleEl = document.getElementById('title');
const hintEl = document.getElementById('hint');
if (titleEl) titleEl.textContent = chrome.i18n.getMessage("popupTitle");
if (hintEl) hintEl.textContent = chrome.i18n.getMessage("popupHint");
// 1. 초기 설정: 저장된 값이 있으면 슬라이더 위치에 반영
chrome.storage.local.get(['geminiWidth', 'cleanView'], function(result) {
if (result.geminiWidth) {
slider.value = result.geminiWidth;
}
if (result.cleanView !== undefined) {
checkbox.checked = result.cleanView;
}
// 초기 상태를 content.js에 전송
updateContent({width: slider.value, cleanView: checkbox.checked});
});
// 2. 슬라이더 조작 감지 및 메시지 전송
slider.addEventListener('input', function() {
updateContent({width: slider.value, cleanView: checkbox.checked});
chrome.storage.local.set({geminiWidth: slider.value});
});
// 3. Checkbox 변화 감지
checkbox.addEventListener('change', function() {
updateContent({width: slider.value, cleanView: checkbox.checked});
chrome.storage.local.set({cleanView: checkbox.checked});
});
// 4. Function to send message to content.js
function updateContent({width, cleanView}) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const tab = tabs[0];
if (!tab || !tab.url.includes("gemini.google.com")) return;
chrome.tabs.sendMessage(tab.id, {
action: "updateSettings",
width: width,
cleanView: cleanView
}).catch(() => {});
});
}
});