-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
251 lines (219 loc) · 9.65 KB
/
content.js
File metadata and controls
251 lines (219 loc) · 9.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
(function() {
'use strict';
// 페이지가 완전히 로드된 후 실행
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initAutofill);
} else {
initAutofill();
}
function initAutofill() {
// POSTECH 의료공제 신청 페이지에서만 실행
if (!isValidMedicalPage()) {
return;
}
// 추가 지연을 두어 동적 콘텐츠 로딩 완료 대기
setTimeout(() => {
loadAndFillData();
}, 1000);
}
function isValidMedicalPage() {
const currentUrl = window.location.href;
const isPosTechDomain = currentUrl.includes('smcp.postech.ac.kr');
const isApplyForDeduction = currentUrl.includes('/apply-for-deduction/');
const hasModEditor = currentUrl.includes('mod=editor');
return isPosTechDomain && isApplyForDeduction && hasModEditor;
}
function loadAndFillData() {
// Chrome Storage에서 사용자 데이터 불러오기
chrome.storage.local.get(['userInfo'], function(result) {
if (chrome.runtime.lastError) {
console.error('POSTECH Medical Autofill - Storage error:', chrome.runtime.lastError);
return;
}
const userData = result.userInfo;
if (!userData) {
console.log('POSTECH Medical Autofill - No user data found');
return;
}
console.log('POSTECH Medical Autofill - Starting autofill process');
fillFormFields(userData);
});
}
function fillFormFields(userData) {
let filledCount = 0;
// 1. 제목 자동완성 - "{이름} 의료공제회 신청"
if (userData.name) {
const titleElement = document.querySelector('#title');
if (titleElement) {
titleElement.value = `${userData.name} 의료공제회 신청`;
titleElement.dispatchEvent(new Event('input', { bubbles: true }));
titleElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled title: ${userData.name} 의료공제회 신청`);
filledCount++;
}
}
// 2. 학과 자동완성
if (userData.department) {
const deptElement = document.querySelector('#dep_selec');
if (deptElement) {
deptElement.value = userData.department;
deptElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled department: ${userData.department}`);
filledCount++;
}
}
// 3. 과정 자동완성
if (userData.course) {
const courseElement = document.querySelector('#cour_selec');
if (courseElement) {
courseElement.value = userData.course;
courseElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled course: ${userData.course}`);
filledCount++;
}
}
// 4. 학번 자동완성
if (userData.studentId) {
const studNumElement = document.querySelector('#stud_num');
if (studNumElement) {
studNumElement.value = userData.studentId;
studNumElement.dispatchEvent(new Event('input', { bubbles: true }));
studNumElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled student ID: ${userData.studentId}`);
filledCount++;
}
}
// 5. 이름 자동완성
if (userData.name) {
const nameElement = document.querySelector('#kboard-input-member-display');
if (nameElement) {
nameElement.value = userData.name;
nameElement.dispatchEvent(new Event('input', { bubbles: true }));
nameElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled name: ${userData.name}`);
filledCount++;
}
}
// 6. 성별 자동완성
if (userData.gender) {
const genderValue = userData.gender === 'male' ? '남' : '여';
const genderElement = document.querySelector(`input[name="kboard_option_sex_selec"][value="${genderValue}"]`);
if (genderElement) {
genderElement.checked = true;
genderElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled gender: ${genderValue}`);
filledCount++;
}
}
// 7. 휴대폰 & e-mail 자동완성
if (userData.phoneEmail) {
const phoneElement = document.querySelector('#phon_num');
if (phoneElement) {
phoneElement.value = userData.phoneEmail;
phoneElement.dispatchEvent(new Event('input', { bubbles: true }));
phoneElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled phone & email: ${userData.phoneEmail}`);
filledCount++;
}
}
// 8. 은행명 자동완성
if (userData.bank) {
const bankElement = document.querySelector('#bank_name');
if (bankElement) {
bankElement.value = userData.bank;
bankElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled bank: ${userData.bank}`);
filledCount++;
}
}
// 9. 계좌번호 자동완성
if (userData.accountNumber) {
const accountElement = document.querySelector('#bank_num');
if (accountElement) {
accountElement.value = userData.accountNumber;
accountElement.dispatchEvent(new Event('input', { bubbles: true }));
accountElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled account number: ${userData.accountNumber}`);
filledCount++;
}
}
// 10. 서명 자동완성 (이름과 동일)
if (userData.name) {
const signElement = document.querySelector('#name_sign');
if (signElement) {
signElement.value = userData.name;
signElement.dispatchEvent(new Event('input', { bubbles: true }));
signElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`POSTECH Medical Autofill - Filled signature: ${userData.name}`);
filledCount++;
}
}
console.log(`POSTECH Medical Autofill - Filled ${filledCount} fields`);
if (filledCount > 0) {
showAutofillNotification();
}
}
function showAutofillNotification() {
showToastNotification('POSTECH 의료공제: 저장된 정보를 불러왔습니다.', 'success');
}
function showToastNotification(message, type = 'success') {
// 알림 div 생성
const notification = document.createElement('div');
const backgroundColor = type === 'success' ? '#c8007a' : '#dc3545';
const icon = type === 'success' ? '✅' : '❌';
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: ${backgroundColor};
color: white;
padding: 15px 20px;
border-radius: 8px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 14px;
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
z-index: 999999;
animation: slideIn 0.3s ease-out;
max-width: 400px;
`;
notification.innerHTML = `
<div style="display: flex; align-items: center; gap: 10px;">
<span style="font-size: 16px;">${icon}</span>
<span>${message}</span>
</div>
`;
// 애니메이션 CSS 추가 (한 번만)
if (!document.querySelector('#postech-toast-styles')) {
const style = document.createElement('style');
style.id = 'postech-toast-styles';
style.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
`;
document.head.appendChild(style);
}
document.body.appendChild(notification);
// 3초 후 알림 제거
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease-out';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 3000);
}
// 메시지 리스너 추가
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message.action === 'showToast') {
showToastNotification(message.message, message.type);
sendResponse({success: true});
}
});
})();