-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
193 lines (159 loc) · 6.04 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Next Poya When?</title>
<link rel="icon" type="image/png" href="/favicon.png">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Helvetica';
padding: 1rem;
}
.centered {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex-grow: 1;
text-align: center;
width: 100%;
}
.centered-row {
margin-bottom: 1rem;
}
#row3 {
margin-top: 40px;
}
#share {
margin-top: 10px;
}
.share-btn {
display: inline-block;
vertical-align: top;
margin-right: 5px;
}
#footer {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 50px;
}
#footer a {
padding: 10px;
}
a:link { text-decoration: none; color: #555555; }
a:visited { text-decoration: none; color: #555555; }
a:hover { text-decoration: none; color: #777777; }
</style>
</head>
<body>
<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.8";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div id="container" class="centered">
<div class="centered">
<div id="row1" class="centered-row"></div>
<div id="row2" class="centered-row"></div>
<div id="row3" class="centered-row"></div>
<div id="share" class="centered-row"></div>
</div>
<div id="footer">
<a href="https://github.com/thameera/poya">Github</a>
<a href="https://twitter.com/thameera">Twitter</a>
<a href="https://status.nextpoyawhen.com">Status</a>
</div>
</div>
<script>
(function() {
const poyadays_orig = REPLACE_ME
const poyadays = poyadays_orig.map(day => new Date(day[0], day[1]-1, day[2]));
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const nextPoya = poyadays.filter(poya => poya-today > 0)[0];
const getDayDiff = (a, b) => Math.floor((b-a)/(1000*60*60*24));
const pad = num => {
const s = '0' + num;
return s.substr(s.length - 2);
}
const getDescriptiveDate = date => {
const day = date.getDay();
const isWeekday = (day > 0) && (day < 6);
const dayDiff = getDayDiff(today, date);
const dayString = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][day];
return {
date: date,
dateStr: date.getFullYear() + '/' + pad(date.getMonth()+1) + '/' + pad(date.getDate()),
dayStr: dayString,
isWeekday: isWeekday,
dayDiff: dayDiff
};
}
const writeOutput = date => {
let str1 = date.dayDiff + ' more day';
str1 += date.dayDiff > 1 ? 's' : '';
let tweetText = str1;
str1 += ' to the next <a href="https://en.wikipedia.org/wiki/Poya">poya</a>';
tweetText += ' to the next poya. ';
document.querySelector('#row1').innerHTML = str1;
let str2
if (date.isWeekday) {
str2 = 'Aaand it\'s a ' + date.dayStr + '!! :)';
} else {
str2 = 'But it\'s a ' + date.dayStr + '!! :(';
}
tweetText += str2;
document.querySelector('#row2').innerHTML = str2;
const str3 = 'Next poya day falls on ' + date.dateStr + '. All poya days are holidays in Sri Lanka!';
document.querySelector('#row3').innerHTML = str3;
const tweet = '<div class="share-btn"><a href="https://twitter.com/share" class="twitter-share-button" data-url="https://nextpoyawhen.com" data-text="' + tweetText + '" data-size="small" data-related="thameera" data-hashtags="lka" data-dnt="true">Tweet</a></div>';
const fbshare = '<div class="share-btn"><div class="fb-share-button" data-href="https://nextpoyawhen.com" data-layout="button_count" data-size="small" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fnextpoyawhen.com%2F&src=sdkpreparse">Share</a></div></div>';
document.querySelector('#share').innerHTML = tweet + fbshare;
loadTwitter();
}
const updateFontSizes = () => {
// This is done to dynamically set height on mobile browsers where URL bar height isn't included in `100vh` property
const body = document.body;
const bodyWidth = body.clientWidth;
body.style.minHeight = `${window.innerHeight}px`;
// Update font sizes of the rows
const row1 = document.getElementById('row1');
const row2 = document.getElementById('row2');
const row3 = document.getElementById('row3');
row1.style.fontSize = `calc(2rem + ${window.innerWidth * 0.01}px)`;
row2.style.fontSize = `calc(1.5rem + ${window.innerWidth * 0.008}px)`;
row3.style.fontSize = `calc(1rem + ${window.innerWidth * 0.004}px)`;
}
const loadTwitter = () => {
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {};
if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id;
js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
t._e = []; t.ready = function(f) { t._e.push(f); };
return t;
}(document, "script", "twitter-wjs"));
}
window.onload = () => {
writeOutput(getDescriptiveDate(nextPoya));
updateFontSizes();
};
window.onresize = updateFontSizes;
})();
</script>
</body>
</html>