Skip to content

Commit 25fb09d

Browse files
feat: sine wave!
BREAKING CHANGE: extra anti-hack protection
1 parent ca620c4 commit 25fb09d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/applause-button.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@ const getClaps = url =>
1010
}
1111
}).then(response => response.text());
1212

13+
14+
const WAVELENGTH = 60 * 5;
15+
const secondsForClap = a => (WAVELENGTH * Math.asin(a / 10)) / (Math.PI * 2);
16+
17+
const computeRequest = clapCount => {
18+
const requiredSeconds = secondsForClap(clapCount);
19+
const serverSeconds = (Date.now() / 1000) % 60;
20+
const delta = requiredSeconds - serverSeconds;
21+
return delta;
22+
}
23+
1324
const updateClaps = (claps, url) =>
1425
// TODO: polyfill for IE (not edge)
1526
fetch(`${API}/update-claps` + (url ? `?url=${url}` : ""), {
1627
method: "POST",
1728
headers: {
1829
"Content-Type": "text/plain"
1930
},
20-
body: JSON.stringify(claps)
31+
body: JSON.stringify(computeRequest(claps))
2132
}).then(response => response.text());
2233

2334
const arrayOfSize = size => new Array(size).fill(undefined);

0 commit comments

Comments
 (0)