-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.js
275 lines (265 loc) · 7.38 KB
/
Code.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// ==============================================
// ACTIVITY CONFIGURATION
// ==============================================
// Defines activities with their associated:
// - emoji: Visual identifier
// - variants: Keywords in different languages (en/tr)
// - category: For color coding and grouping
// ==============================================
const activities = {
interview: {
emoji: "🎙️",
variants: { en: ["interview"], tr: [] },
category: "interview",
},
flight: {
emoji: "🛫",
variants: { en: ["flight"], tr: [] },
category: "travel",
},
bus: {
emoji: "🚌",
variants: { en: ["bus"], tr: [] },
category: "travel",
},
train: {
emoji: "🚆",
variants: { en: ["journey", "trip"], tr: [] },
category: "travel",
},
metro: {
emoji: "🚇",
variants: { en: ["travel"], tr: [] },
category: "travel",
},
stay: {
emoji: "🏠",
variants: { en: ["stay"], tr: [] },
category: "accommodation",
},
barber: {
emoji: "💈",
variants: {
en: ["barber"],
tr: ["berber", "sac kestir"],
},
category: "wellness",
},
workout: {
emoji: "💪",
variants: { en: ["holy shred"], tr: [] },
category: "fitness",
},
cycling: {
emoji: "🚵",
variants: { en: ["holy ride"], tr: [] },
category: "fitness",
},
spa: {
emoji: "🧖",
variants: { en: ["holy wellness"], tr: [] },
category: "wellness",
},
padel: {
emoji: "🏸",
variants: { en: ["padel"], tr: [] },
category: "fitness",
},
meeting: {
emoji: "🤝",
variants: { en: ["meeting"], tr: [] },
category: "personal",
},
coffee: {
emoji: "☕",
variants: { en: ["catch-up"], tr: [] },
category: "social",
},
videoCall: {
emoji: "📹",
variants: { en: ["video call"], tr: [] },
category: "communication",
},
phone: {
emoji: "📞",
variants: { en: ["call"], tr: ["ara"] },
category: "communication",
},
social: {
emoji: "🎉",
variants: { en: ["sosyal aktivite"], tr: [] },
category: "social",
},
casino: {
emoji: "🎰",
variants: { en: ["casino"], tr: [] },
category: "entertainment",
},
sports: {
emoji: "🏅",
variants: { en: ["paris 2024"], tr: [] },
category: "event",
},
appointment: {
emoji: "📅",
variants: {
en: ["appointment", "reservation", "start date"],
tr: ["randevu"],
},
category: "schedule",
},
repair: {
emoji: "🛠️",
variants: {
en: ["repair"],
tr: ["tamir"],
},
category: "maintenance",
},
payment: {
emoji: "💸",
variants: { en: ["payment"], tr: [] },
category: "finance",
},
ticket: {
emoji: "🎫",
variants: { en: ["ticket"], tr: [] },
category: "entertainment",
},
massage: {
emoji: "💆",
variants: { en: ["massage"], tr: ["masaj"] },
category: "wellness",
},
action: {
emoji: "🎯",
variants: { en: [], tr: ["aksiyon al"] },
category: "reminders",
},
dinner: {
emoji: "🍽️",
variants: {
en: ["dinner", "meal"],
tr: ["yemek", "yeme içme"],
},
category: "food",
},
utilities: {
emoji: "🔌",
variants: {
en: ["gas and electricity"],
tr: [],
},
category: "maintenance",
},
};
// ==============================================
// CATEGORY COLOR MAPPING
// ==============================================
// Maps activity categories to Google Calendar's
// predefined event colors for visual organization
// ==============================================
const categoryColors = {
food: CalendarApp.EventColor.GRAY,
wellness: CalendarApp.EventColor.BLUE,
schedule: CalendarApp.EventColor.PALE_BLUE,
finance: CalendarApp.EventColor.GREEN,
travel: CalendarApp.EventColor.CYAN,
social: CalendarApp.EventColor.PALE_GREEN,
personal: CalendarApp.EventColor.MAUVE,
communication: CalendarApp.EventColor.MAUVE,
reminders: CalendarApp.EventColor.ORANGE,
maintenance: CalendarApp.EventColor.ORANGE,
fitness: CalendarApp.EventColor.BLUE,
accommodation: CalendarApp.EventColor.CYAN,
entertainment: CalendarApp.EventColor.PALE_GREEN,
event: CalendarApp.EventColor.RED,
interview: CalendarApp.EventColor.YELLOW,
};
// ==============================================
// EMOJI DETECTION
// ==============================================
// Searches event title for activity keywords and
// returns corresponding emoji if found
// Returns empty string if no match
// ==============================================
function getEmoji(input) {
const lowerInput = input.toLowerCase();
return (
Object.values(activities).find((activity) =>
Object.values(activity.variants).some((langVariants) =>
langVariants.some((variant) =>
new RegExp(`\\b${variant}\\b`, "i").test(lowerInput)
)
)
)?.emoji || ""
);
}
// ==============================================
// COLOR DETECTION
// ==============================================
// Searches event title for activity keywords and
// returns corresponding calendar color if found
// Returns null if no match
// ==============================================
function getEventColor(input) {
const lowerInput = input.toLowerCase();
const activity = Object.values(activities).find((activity) =>
Object.values(activity.variants).some((langVariants) =>
langVariants.some((variant) =>
new RegExp(`\\b${variant}\\b`, "i").test(lowerInput)
)
)
);
return activity ? categoryColors[activity.category] : null;
}
// ==============================================
// CALENDAR EVENT PROCESSOR
// ==============================================
// Main function that:
// 1. Gets events from specified date range
// 2. Adds emojis to event titles if missing
// 3. Sets event colors based on categories
// 4. Logs all changes (real or simulated)
// ==============================================
function ColorEvents() {
const isDevelopment = false;
const today = new Date();
const nextThreeMonths = new Date();
nextThreeMonths.setMonth(nextThreeMonths.getMonth() + 3);
const [startDate, endDate] = isDevelopment
? [new Date("2025-01-26"), new Date("2025-01-28")]
: [today, nextThreeMonths];
CalendarApp.getCalendarsByName("main").forEach((calendar) => {
calendar.getEvents(startDate, endDate).forEach((event) => {
const originalTitle = event.getTitle();
// Get emoji and color (language-agnostic)
const emoji = getEmoji(originalTitle);
const color = getEventColor(originalTitle);
const newTitle =
emoji && !originalTitle.startsWith(emoji)
? `${emoji} ${originalTitle}`
: originalTitle;
// Update event if title or color changes needed
if (newTitle !== originalTitle || color) {
try {
if (!isDevelopment) {
if (newTitle !== originalTitle) event.setTitle(newTitle);
if (color) event.setColor(color);
}
const action = isDevelopment ? "Would update" : "Updated";
const colorName =
Object.entries(CalendarApp.EventColor).find(
([_, val]) => val === color
)?.[0] || "NO_COLOR";
Logger.log(`${action}:
Original: ${originalTitle}
New: ${newTitle}
Color: ${colorName} (${color})`);
} catch (error) {
Logger.log(`Error updating ${originalTitle}: ${error}`);
}
}
});
});
}