1
1
/* 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 = {
3
3
YESTERDAY : "yesterday" ,
4
4
LAST_WEEK : "last week" ,
5
5
LAST_MONTH : "last month" ,
6
6
LAST_YEAR : "last year" ,
7
7
SKIP : "skip"
8
- } , PREVIOUS_DATES_ARRAY = Object . values ( PREVIOUS_DATES ) , EMAIL_TEMPLATE = {
8
+ } ;
9
+ Object . values ( PREVIOUS_DATES ) ;
10
+ const EMAIL_TEMPLATE = {
9
11
TEMPLATE_1 : {
10
12
BODY : [
11
13
"<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>"
12
14
] . join ( `
13
15
` ) ,
14
16
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>` ,
16
18
"<hr style='margin-top: 20px;margin-bottom: 20px;border: 0;border-top: 2px=solid whiteSmoke;'>" ,
17
19
`<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>`
18
20
] . join ( `
@@ -31,7 +33,7 @@ function mitime() {
31
33
to : alias2
32
34
} ,
33
35
action : {
34
- addLabelIds : [ mailLabelIds == null ? void 0 : mailLabelIds [ MITIME_LABEL ] ] ,
36
+ addLabelIds : [ mailLabelIds == null ? void 0 : mailLabelIds [ MITIME ] ] ,
35
37
removeLabelIds : [ "INBOX" , "UNREAD" ]
36
38
}
37
39
} ,
@@ -40,7 +42,7 @@ function mitime() {
40
42
from : alias2
41
43
} ,
42
44
action : {
43
- addLabelIds : [ mailLabelIds == null ? void 0 : mailLabelIds [ MITIME_LABEL ] ]
45
+ addLabelIds : [ mailLabelIds == null ? void 0 : mailLabelIds [ MITIME ] ]
44
46
}
45
47
}
46
48
} ) ;
@@ -139,32 +141,11 @@ function mitime() {
139
141
day : "numeric"
140
142
} ) ;
141
143
}
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 } ` ;
168
149
let body = EMAIL_TEMPLATE . TEMPLATE_1 . BODY ;
169
150
const footer = EMAIL_TEMPLATE . TEMPLATE_1 . FOOTER ;
170
151
body += footer , sendEmail ( user , alias , title , body ) ;
@@ -185,6 +166,7 @@ function doGet() {
185
166
<h1>✏️ ${ MITIME } setup completed.</h1>
186
167
<p>You should receive an email from ${ MITIME } in a few minutes. If you don't see it, check your spam folder.</p>
187
168
<br />
169
+ <p>For more information about ${ MITIME } , visit <a href="https://github.com/pkgacek/mitime">GitHub</a>.</p>
188
170
<p>Enjoy!</p>
189
171
</div>
190
172
` ) ;
0 commit comments