diff options
-rw-r--r-- | static/script.js | 19 |
1 files 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<span class="byline">—<a href="${challenge.link}">${challenge.title}</a>\n\t\t${challenge.collection}, ${challenge.author}</span>` - 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) { |