// popup.js - 팝업 스크립트 document.addEventListener('DOMContentLoaded', function() { const changeColorBtn = document.getElementById('changeColor'); const getTextBtn = document.getElementById('getText'); const status = document.getElementById('status'); // 배경색 변경 버튼 이벤트 changeColorBtn.addEventListener('click', async () => { try { const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); // Content script에 메시지 전송 chrome.tabs.sendMessage(tab.id, { action: 'changeBackgroundColor', color: getRandomColor() }, (response) => { if (response && response.success) { status.textContent = '배경색이 변경되었습니다!'; status.style.backgroundColor = '#d4edda'; status.style.color = '#155724'; } }); } catch (error) { console.error('Error:', error); status.textContent = '오류가 발생했습니다.'; status.style.backgroundColor = '#f8d7da'; status.style.color = '#721c24'; } }); // 텍스트 가져오기 버튼 이벤트 getTextBtn.addEventListener('click', async () => { try { const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); chrome.tabs.sendMessage(tab.id, { action: 'getPageText' }, (response) => { if (response && response.text) { status.textContent = `페이지 텍스트 길이: ${response.text.length}자`; status.style.backgroundColor = '#d1ecf1'; status.style.color = '#0c5460'; } }); } catch (error) { console.error('Error:', error); } }); // 랜덤 색상 생성 함수 function getRandomColor() { const colors = ['#ffcccb', '#add8e6', '#90ee90', '#ffb6c1', '#ffd700']; return colors[Math.floor(Math.random() * colors.length)]; } // Background script에서 저장된 데이터 로드 chrome.storage.sync.get(['extensionData'], (result) => { if (result.extensionData) { status.textContent = '이전 데이터가 로드되었습니다.'; } }); });