elykia 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ const CountdownTimer = (() => {
2
+ const config = {
3
+ targetDate: "2025-12-20",
4
+ targetName: "考研",
5
+ units: {
6
+ day: { text: "今日", divider: 1, unit: "小时" },
7
+ week: { text: "本周", divider: 24, unit: "天" },
8
+ month: { text: "本月", divider: 24, unit: "天" },
9
+ year: { text: "本年", divider: 24, unit: "天" }
10
+ }
11
+ };
12
+
13
+ function getTimeUnit(unit) {
14
+ const now = new Date();
15
+ const start = new Date(now.setHours(0, 0, 0, 0));
16
+ const end = new Date(now.setHours(23, 59, 59, 999));
17
+
18
+ if (unit === 'day') {
19
+ const currentHour = new Date().getHours();
20
+ const remaining = 24 - currentHour;
21
+ const percentage = (currentHour / 24) * 100;
22
+
23
+ return {
24
+ name: config.units[unit].text,
25
+ remaining: remaining,
26
+ percentage: percentage.toFixed(2),
27
+ unit: config.units[unit].unit
28
+ };
29
+ }
30
+
31
+ const ranges = {
32
+ week: () => {
33
+ start.setDate(start.getDate() - start.getDay());
34
+ end.setDate(end.getDate() - end.getDay() + 6);
35
+ },
36
+ month: () => {
37
+ start.setDate(1);
38
+ end.setMonth(end.getMonth() + 1, 0);
39
+ },
40
+ year: () => {
41
+ start.setMonth(0, 1);
42
+ end.setMonth(11, 31);
43
+ }
44
+ };
45
+ ranges[unit]?.();
46
+
47
+ const total = unit === "day" ? 24 : Math.floor((end - start) / 86400000) + 1;
48
+ const passed = Math.floor((now - start) / (3600000 * config.units[unit].divider));
49
+ const percentage = (passed / total) * 100;
50
+
51
+ return {
52
+ name: config.units[unit].text,
53
+ remaining: total - passed,
54
+ percentage: percentage.toFixed(2),
55
+ unit: config.units[unit].unit
56
+ };
57
+ }
58
+
59
+ function updateCountdown() {
60
+ const elements = ['eventName', 'eventDate', 'daysUntil', 'countRight']
61
+ .map(id => document.getElementById(id));
62
+
63
+ if (elements.some(el => !el)) return;
64
+
65
+ const [eventName, eventDate, daysUntil, countRight] = elements;
66
+ const timeData = Object.keys(config.units).reduce((acc, unit) => ({...acc, [unit]: getTimeUnit(unit)}), {});
67
+ const daysRemaining = Math.round((new Date(config.targetDate) - new Date().setHours(0,0,0,0)) / 86400000);
68
+
69
+ eventName.textContent = config.targetName;
70
+ eventDate.textContent = config.targetDate;
71
+ daysUntil.textContent = daysRemaining;
72
+ countRight.innerHTML = Object.entries(timeData)
73
+ .map(([_, item]) => `
74
+ <div class="cd-count-item">
75
+ <div class="cd-item-name">${item.name}</div>
76
+ <div class="cd-item-progress">
77
+ <div class="cd-progress-bar" style="width: ${item.percentage}%; opacity: ${item.percentage/100}"></div>
78
+ <span class="cd-percentage ${item.percentage >= 46 ? 'cd-many' : ''}">${item.percentage}%</span>
79
+ <span class="cd-remaining ${item.percentage >= 60 ? 'cd-many' : ''}">
80
+ <span class="cd-tip">还剩</span>${item.remaining}<span class="cd-tip">${item.unit}</span>
81
+ </span>
82
+ </div>
83
+ </div>
84
+ `).join('');
85
+ }
86
+
87
+ function injectStyles() {
88
+ const styles = `
89
+ .card-countdown .item-content {
90
+ display: flex;
91
+ }
92
+ .cd-count-left {
93
+ position: relative;
94
+ display: flex;
95
+ flex-direction: column;
96
+ margin-right: 0.8rem;
97
+ line-height: 1.5;
98
+ align-items: center;
99
+ justify-content: center;
100
+ }
101
+ .cd-count-left .cd-text {
102
+ font-size: 14px;
103
+ }
104
+ .cd-count-left .cd-name {
105
+ font-weight: bold;
106
+ font-size: 18px;
107
+ }
108
+ .cd-count-left .cd-time {
109
+ font-size: 30px;
110
+ font-weight: bold;
111
+ color: var(--anzhiyu-main);
112
+ }
113
+ .cd-count-left .cd-date {
114
+ font-size: 12px;
115
+ opacity: 0.6;
116
+ }
117
+ .cd-count-left::after {
118
+ content: "";
119
+ position: absolute;
120
+ right: -0.8rem;
121
+ width: 2px;
122
+ height: 80%;
123
+ background-color: var(--anzhiyu-main);
124
+ opacity: 0.5;
125
+ }
126
+ .cd-count-right {
127
+ flex: 1;
128
+ margin-left: .8rem;
129
+ display: flex;
130
+ flex-direction: column;
131
+ justify-content: space-between;
132
+ }
133
+ .cd-count-item {
134
+ display: flex;
135
+ flex-direction: row;
136
+ align-items: center;
137
+ height: 24px;
138
+ }
139
+ .cd-item-name {
140
+ font-size: 14px;
141
+ margin-right: 0.8rem;
142
+ white-space: nowrap;
143
+ }
144
+ .cd-item-progress {
145
+ position: relative;
146
+ display: flex;
147
+ flex-direction: row;
148
+ align-items: center;
149
+ justify-content: space-between;
150
+ height: 100%;
151
+ width: 100%;
152
+ border-radius: 8px;
153
+ background-color: var(--anzhiyu-background);
154
+ overflow: hidden;
155
+ }
156
+ .cd-progress-bar {
157
+ height: 100%;
158
+ border-radius: 8px;
159
+ background-color: var(--anzhiyu-main);
160
+ }
161
+ .cd-percentage,
162
+ .cd-remaining {
163
+ position: absolute;
164
+ font-size: 12px;
165
+ margin: 0 6px;
166
+ transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
167
+ }
168
+ .cd-many {
169
+ color: #fff;
170
+ }
171
+ .cd-remaining {
172
+ opacity: 0;
173
+ transform: translateX(10px);
174
+ }
175
+ .card-countdown .item-content:hover .cd-remaining {
176
+ transform: translateX(0);
177
+ opacity: 1;
178
+ }
179
+ .card-countdown .item-content:hover .cd-percentage {
180
+ transform: translateX(-10px);
181
+ opacity: 0;
182
+ }
183
+ `;
184
+
185
+ const styleSheet = document.createElement("style");
186
+ styleSheet.textContent = styles;
187
+ document.head.appendChild(styleSheet);
188
+ }
189
+
190
+ let timer;
191
+ const start = () => {
192
+ injectStyles();
193
+ updateCountdown();
194
+ timer = setInterval(updateCountdown, 600000);
195
+ };
196
+
197
+ ['pjax:complete', 'DOMContentLoaded'].forEach(event => document.addEventListener(event, start));
198
+ document.addEventListener('pjax:send', () => timer && clearInterval(timer));
199
+
200
+ return { start, stop: () => timer && clearInterval(timer) };
201
+ })();
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file