From f4f0f93466771dd277a4a847224c6da626f65590 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Sun, 27 Feb 2022 01:32:55 -0500 Subject: date --- static/script.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/static/script.js b/static/script.js index caea216..16296a2 100644 --- a/static/script.js +++ b/static/script.js @@ -195,9 +195,8 @@ function winGame(challenge) { document.getElementById('btns').style = 'display: none;' document.getElementById('meter').innerText = challenge.meter document.getElementById('ctx').innerHTML = challenge.ctx.replaceAll(/^(.*)/gm, ' $1') + `\n\t${challenge.title}\n\t\t${challenge.collection}, ${challenge.author}` - var date = new Date().toISOString().slice(0, 10) var firstguess = Object.values(guesses[0]).join(' ') - document.getElementById('share').value = `I solved the ${date} Prosodyle at cyfraeviolae.org/prosodyle. My first guess was: "${firstguess}".` + document.getElementById('share').value = `I solved Prosodyle #${getChallengeIdx()+1} at cyfraeviolae.org/prosodyle. My first guess was: "${firstguess}."` } function keyHandler(key) { @@ -248,15 +247,23 @@ document.addEventListener('mousedown', function(e) { } }) -function getDailyChallenge() { - // begin snippet from https://stackoverflow.com/a/8619946 + +// from https://stackoverflow.com/a/8619946 +function getDayOfYear() { var now = new Date(); var start = new Date(now.getFullYear(), 0, 0); var diff = now - start; var oneDay = 1000 * 60 * 60 * 24; var day = Math.floor(diff / oneDay); - // end snippet - return challenges[day-57] + return day; +} + +function getChallengeIdx() { + return getDayOfYear() - 57 +} + +function getDailyChallenge() { + return challenges[getChallengeIdx()] } document.getElementById('copy').addEventListener('click', function(e) { -- cgit v1.2.3