Skip to content

Commit 56ca14c

Browse files
committed
[Fix] update timer
1 parent 74e46b8 commit 56ca14c

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

Code.js

+13-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/* minified */
2-
const MITIME = "Mitime", MITIME_LABEL = MITIME.toLowerCase(), MITIME_LABEL_URL = `https://mail.google.com/mail/u/0/#label/${MITIME_LABEL}`, MITIME_SCRIPT_ID = ScriptApp.getScriptId(), MITIME_TRIGGER_SETTINGS_URL = `https://script.google.com/home/projects/${MITIME_SCRIPT_ID}/triggers`, PREVIOUS_DATES = {
2+
const MITIME = "mitime", MITIME_URL = `https://mail.google.com/mail/u/0/#label/${MITIME}`, MITIME_SCRIPT_ID = ScriptApp.getScriptId(), MITIME_TRIGGER_SETTINGS_URL = `https://script.google.com/home/projects/${MITIME_SCRIPT_ID}/triggers`, PREVIOUS_DATES = {
33
YESTERDAY: "yesterday",
44
LAST_WEEK: "last week",
55
LAST_MONTH: "last month",
66
LAST_YEAR: "last year",
77
SKIP: "skip"
8-
}, PREVIOUS_DATES_ARRAY = Object.values(PREVIOUS_DATES), EMAIL_TEMPLATE = {
8+
};
9+
Object.values(PREVIOUS_DATES);
10+
const EMAIL_TEMPLATE = {
911
TEMPLATE_1: {
1012
BODY: [
1113
"<p>mitime helps you remember what's happened in your life. Reply to this email with your entry and we'll add it to your timeline.</p>"
1214
].join(`
1315
`),
1416
FOOTER: [
15-
`<p>You can check out your entries here: <a href="${MITIME_LABEL_URL}">${MITIME_LABEL_URL}</a></p>`,
17+
`<p>You can check out your entries here: <a href="${MITIME_URL}">${MITIME_URL}</a></p>`,
1618
"<hr style='margin-top: 20px;margin-bottom: 20px;border: 0;border-top: 2px=solid whiteSmoke;'>",
1719
`<p><i>P.S. You'll receive emails every day. You can change this by changing the <a href="${MITIME_TRIGGER_SETTINGS_URL}">trigger settings</a>.</i></p>`
1820
].join(`
@@ -31,7 +33,7 @@ function mitime() {
3133
to: alias2
3234
},
3335
action: {
34-
addLabelIds: [mailLabelIds == null ? void 0 : mailLabelIds[MITIME_LABEL]],
36+
addLabelIds: [mailLabelIds == null ? void 0 : mailLabelIds[MITIME]],
3537
removeLabelIds: ["INBOX", "UNREAD"]
3638
}
3739
},
@@ -40,7 +42,7 @@ function mitime() {
4042
from: alias2
4143
},
4244
action: {
43-
addLabelIds: [mailLabelIds == null ? void 0 : mailLabelIds[MITIME_LABEL]]
45+
addLabelIds: [mailLabelIds == null ? void 0 : mailLabelIds[MITIME]]
4446
}
4547
}
4648
});
@@ -139,32 +141,11 @@ function mitime() {
139141
day: "numeric"
140142
});
141143
}
142-
function getPreviousDate(index2, locale2) {
143-
if (index2 == null)
144-
throw new MitimeError(getPreviousDate, "Index is not defined");
145-
if (!locale2)
146-
throw new MitimeError(getPreviousDate, "Locale is not defined");
147-
const date2 = PREVIOUS_DATES_ARRAY[index2];
148-
let d = /* @__PURE__ */ new Date();
149-
return date2 === PREVIOUS_DATES.YESTERDAY && d.setDate(d.getDate() - 1), date2 === PREVIOUS_DATES.LAST_WEEK && d.setDate(d.getDate() - 7), date2 === PREVIOUS_DATES.LAST_MONTH && d.setMonth(d.getMonth() - 1), date2 === PREVIOUS_DATES.LAST_YEAR && d.setFullYear(d.getFullYear() - 1), date2 === PREVIOUS_DATES.SKIP ? null : (d = getDate(locale2, new Date(d)), {
150-
name: `${date2} (${d})`,
151-
date: d
152-
});
153-
}
154-
function getRandomIndex(min, max) {
155-
if (min == null)
156-
throw new MitimeError(getRandomIndex, "Min is not defined");
157-
if (max == null)
158-
throw new MitimeError(getRandomIndex, "Max is not defined");
159-
const parsedMin = Math.ceil(min), parsedMax = Math.floor(max);
160-
return Math.floor(Math.random() * (parsedMax - parsedMin + 1) + parsedMin);
161-
}
162-
const user = Session.getEffectiveUser().getEmail(), locale = Session.getActiveUserLocale(), alias = createAlias(user, MITIME_LABEL);
163-
checkLabels([MITIME_LABEL]);
164-
const { labels } = Gmail.Users.Labels.list(user), labelsIds = getLabelIds(labels, [MITIME_LABEL]), filters = Gmail.Users.Settings.Filters.list(user).filter, filterCriteria = getFilters(alias, labelsIds);
165-
checkFilters(filters, filterCriteria, user), removeEmails(MITIME_LABEL, alias, user);
166-
const date = getDate(locale), title = `✏️ ${MITIME} for ${date}`, index = getRandomIndex(0, PREVIOUS_DATES_ARRAY.length - 1);
167-
getPreviousDate(index, locale);
144+
const user = Session.getEffectiveUser().getEmail(), locale = Session.getActiveUserLocale(), alias = createAlias(user, MITIME);
145+
checkLabels([MITIME]);
146+
const { labels } = Gmail.Users.Labels.list(user), labelsIds = getLabelIds(labels, [MITIME]), filters = Gmail.Users.Settings.Filters.list(user).filter, filterCriteria = getFilters(alias, labelsIds);
147+
checkFilters(filters, filterCriteria, user), removeEmails(MITIME, alias, user);
148+
const date = getDate(locale), title = `✏️ ${MITIME} for ${date}`;
168149
let body = EMAIL_TEMPLATE.TEMPLATE_1.BODY;
169150
const footer = EMAIL_TEMPLATE.TEMPLATE_1.FOOTER;
170151
body += footer, sendEmail(user, alias, title, body);
@@ -185,6 +166,7 @@ function doGet() {
185166
<h1>✏️ ${MITIME} setup completed.</h1>
186167
<p>You should receive an email from ${MITIME} in a few minutes. If you don't see it, check your spam folder.</p>
187168
<br />
169+
<p>For more information about ${MITIME}, visit <a href="https://github.com/pkgacek/mitime">GitHub</a>.</p>
188170
<p>Enjoy!</p>
189171
</div>
190172
`);

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export function doGet() {
346346

347347
if (!functionName) throw new MitimeError(setupTrigger, 'Function name is not defined');
348348
deleteTriggers();
349-
ScriptApp.newTrigger(functionName).timeBased().everyMinutes(5).create();
349+
ScriptApp.newTrigger(functionName).timeBased().everyDays(1).atHour(9).create();
350350
}
351351

352352
setupTrigger(mitime.name);

0 commit comments

Comments
 (0)