Skip to content

Commit 722fa8c

Browse files
authored
Merge pull request #9 from CCU-Class/new_frontend
new version frontend 1
2 parents 52285d2 + 6e78f9e commit 722fa8c

File tree

3 files changed

+88
-19
lines changed

3 files changed

+88
-19
lines changed

src/css/input.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
11
@import "tailwindcss";
2+
3+
@keyframes dots {
4+
0% {
5+
content: "";
6+
}
7+
33% {
8+
content: ".";
9+
}
10+
66% {
11+
content: "..";
12+
}
13+
100% {
14+
content: "...";
15+
}
16+
}
17+
.loading-dots::after {
18+
display: inline-block;
19+
animation: dots 1.2s steps(3, end) infinite;
20+
content: "";
21+
}

src/js/popup.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ function getDate() {
4242
return { year, month, day };
4343
}
4444

45+
function updateResult(status, message) {
46+
const el = document.getElementById("result");
47+
48+
el.className =
49+
"text-sm whitespace-pre-wrap text-left w-full px-3 py-2 rounded-md border transition";
50+
51+
if (status === "success") {
52+
el.classList.add("bg-green-50", "text-green-700", "border-green-300");
53+
} else if (status === "error") {
54+
el.classList.add("bg-red-50", "text-red-700", "border-red-300");
55+
} else if (status === "loading") {
56+
el.classList.add("bg-orange-50", "text-orange-700", "border-orange-300", "loading-dots");
57+
}
58+
59+
el.textContent = message;
60+
}
61+
4562
function setupEventListeners() {
4663
document.getElementById("exportBtn").addEventListener("click", async () => {
4764
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
@@ -76,22 +93,27 @@ function setupEventListeners() {
7693
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
7794
chrome.tabs.sendMessage(tabs[0].id, { action: "get_sesskey" }, async (res) => {
7895
const sesskey = res?.sesskey;
96+
const resultEl = document.getElementById("result");
97+
7998
if (!sesskey) {
8099
console.log("no touch sesskey");
81-
document.getElementById("result").textContent =
82-
"無法獲取 sesskey,請先登入 Moodle 或者重新整理頁面";
100+
updateResult("error", "無法獲取 sesskey,請先登入 Moodle 或重新整理頁面");
83101
return;
84102
}
103+
85104
console.log("import");
86-
document.getElementById("result").textContent = "匯入作業進入行事曆中...";
105+
updateResult("loading", "匯入作業進入行事曆中");
106+
87107
const { year, month, day } = getDate();
108+
88109
chrome.runtime.sendMessage(
89110
{ action: "import_events", sesskey, year, month, day },
90111
(res) => {
112+
resultEl.classList.remove("loading-dots");
91113
if (res?.ok) {
92-
document.getElementById("result").textContent = `成功匯入 ${res.count} 個作業事件`;
114+
updateResult("success", `成功匯入 ${res.count} 個作業事件`);
93115
} else {
94-
document.getElementById("result").textContent = res?.error || "發生錯誤,請稍後再試";
116+
updateResult("error", res?.error || "發生錯誤,請稍後再試");
95117
}
96118
}
97119
);

src/popup.html

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<!doctype html>
2-
<html>
2+
<html lang="zh-TW">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link href="./css/output.css" rel="stylesheet" />
7+
<title>CCU Calendar Helper</title>
78
</head>
8-
<body class="p-4 w-60 flex items-center justify-center flex-col bg-white shadow-md rounded-lg">
9-
<h1 class="text-xl font-bold">CCU Calendar Helper</h1>
10-
<div class="my-2 flex items-center space-x-2">
9+
<body
10+
class="p-6 w-80 bg-white text-gray-800 shadow-lg rounded-xl flex flex-col items-center font-sans"
11+
>
12+
<h1 class="text-xl font-semibold text-[#e88842] mb-2 whitespace-nowrap">CCU Calendar Helper</h1>
13+
<div class="w-full border-b border-[#e8b68d] my-2"></div>
14+
15+
<div class="my-3 w-full flex justify-center items-center space-x-2">
1116
<input
1217
type="number"
1318
id="yearInput"
1419
min="1992"
15-
class="w-20 px-2 py-1 text-center border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-violet-500 focus:border-violet-500"
20+
class="w-20 px-2 py-1 text-center border border-[#e8b68d] rounded-md bg-white focus:outline-none focus:ring-1 focus:ring-[#e88842]"
1621
placeholder=""
1722
/>
1823
<span class="text-gray-700"></span>
@@ -21,38 +26,60 @@ <h1 class="text-xl font-bold">CCU Calendar Helper</h1>
2126
id="monthInput"
2227
min="1"
2328
max="12"
24-
class="w-16 px-2 py-1 text-center border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-violet-500 focus:border-violet-500"
29+
class="w-16 px-2 py-1 text-center border border-[#e8b68d] rounded-md bg-white focus:outline-none focus:ring-1 focus:ring-[#e88842]"
2530
placeholder=""
2631
/>
2732
<span class="text-gray-700"></span>
2833
</div>
34+
2935
<button
3036
id="exportBtn"
31-
class="bg-violet-400 text-white px-4 py-2 my-2 rounded-md shadow-md cursor-pointer hover:bg-violet-700 focus:outline-none focus:ring-2 focus:ring-violet-500"
37+
class="w-full bg-[#f4a261] text-white px-4 py-2 my-2 rounded-full hover:bg-[#e07628] transition"
3238
>
3339
匯出作業行事曆檔案
3440
</button>
3541
<button
3642
id="importBtn"
37-
class="bg-gray-400 text-white px-4 py-2 my-2 rounded cursor-pointer hover:bg-gray-700"
43+
class="w-full bg-[#b0b0b0] text-white px-4 py-2 my-2 rounded-full hover:bg-[#8c8c8c] transition"
3844
>
3945
更新事件至行事曆
4046
</button>
41-
<div class="flex items-center my-2 invisible" id="autoImportContainer">
47+
48+
<div class="flex items-center my-2" id="autoImportContainer">
4249
<label for="autoImportToggle" class="mr-2 text-sm text-gray-700">自動匯入</label>
4350
<input
4451
type="checkbox"
4552
id="autoImportToggle"
46-
class="w-5 h-5 text-violet-500 border-gray-300 rounded focus:ring-violet-500"
53+
class="w-5 h-5 accent-[#e88842] rounded focus:ring-[#e88842]"
4754
checked
4855
/>
4956
</div>
50-
<pre id="result" class="text-sm my-2 whitespace-pre-wrap"></pre>
51-
<div class="text-gray-600 text-sm text-center">
57+
58+
<pre
59+
id="result"
60+
class="text-sm whitespace-pre-wrap text-left w-full px-3 py-2 rounded-md border transition hidden"
61+
></pre>
62+
<p class="text-gray-700 text-sm text-center my-2 leading-relaxed">
5263
將 ECourse2 的行事曆匯出為 iCalendar 檔案,並匯入到 Google 行事曆中。
53-
</div>
64+
</p>
65+
66+
<div class="w-full border-t border-[#e8b68d] my-3"></div>
67+
68+
<footer class="text-center text-xs text-gray-500 w-full">
69+
<div class="flex justify-center gap-x-4">
70+
<a href="mailto:PineappleSchedule2023@gmail.com" class="text-[#e88842] hover:underline"
71+
>聯絡我們</a
72+
>
73+
<a
74+
href="https://forms.gle/your-google-form-link"
75+
target="_blank"
76+
class="text-[#e88842] hover:underline"
77+
>
78+
提供回饋
79+
</a>
80+
</div>
81+
</footer>
5482

55-
<!-- Use type="module" for ES module support -->
5683
<script type="module" src="./js/popup.js"></script>
5784
</body>
5885
</html>

0 commit comments

Comments
 (0)