forked from plz-graduate/KW-Graduation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
106 lines (97 loc) · 2.91 KB
/
background.js
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
function fetchData() {
// POST 요청1 - AtnlcScreSungjukTot
fetch('https://klas.kw.ac.kr/std/cps/inqire/AtnlcScreSungjukTot.do', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
// 데이터를 chrome.storage에 저장
chrome.storage.local.set({ AtnlcScreSungjukTot: data }, () => {
});
})
.catch(error => {
console.error('취득 학점 정보를 가져오는데 실패하였습니다:', error);
});
//POST 요청2 - AtnlcScreSungjukInfo
fetch('https://klas.kw.ac.kr/std/cps/inqire/AtnlcScreSungjukInfo.do', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
// 데이터를 chrome.storage에 저장
chrome.storage.local.set({ AtnlcScreSungjukInfo: data }, () => {
});
})
.catch(error => {
console.error('성적 정보를 가져오는데 실패하였습니다:', error);
});
//POST 요청3 - AtnlcScreHakjukInfo
fetch('https://klas.kw.ac.kr/std/cps/inqire/AtnlcScreHakjukInfo.do', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
// 데이터를 chrome.storage에 저장
chrome.storage.local.set({ AtnlcScreHakjukInfo: data }, () => {
});
})
.catch(error => {
console.error('학적 정보를 가져오는데 실패하였습니다:', error);
});
// POST 요청4 - GyoyangIsuInfo
fetch('https://klas.kw.ac.kr/std/cps/inqire/GyoyangIsuInfo.do', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
chrome.storage.local.set({GyoyangIsuInfo: data }, () => {
});
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
// background.js
function openNewTab(url, hakbun) {
const newURL = `${url}?hakbun=${hakbun}`;
chrome.tabs.create({ url: newURL });
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
fetchData();
if (message.action === "openNewTab") {
switch(message.hakgwa) {
case "정보융합학부":
openNewTab("html/informationConvergence.html", message.hakbun);
break;
case "전자공학과":
openNewTab("html/electronic.html", message.hakbun);
break;
case "경영학부":
openNewTab("html/bussiness.html", message.hakbun);
break;
case "성적계산기":
openNewTab("html/new.html");
break;
default:
console.log("해당 학과 정보를 처리할 수 없습니다.");
}
} else {
console.log("알 수 없는 액션입니다.");
}
});