-
Notifications
You must be signed in to change notification settings - Fork 0
/
affirmation-widget.js
34 lines (33 loc) · 1.43 KB
/
affirmation-widget.js
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
async function affirmationImage() {
let affirmations = await fetch("./affirmationSheetUK.json");
affirmations = await affirmations.json();
let matchDate = new Date().toISOString().slice(5, 10);
let affirmationDate;
let dailyAffirmation;
let dailyAffirmationSource;
let affirmationAlt;
let affirmationTitle;
let affirmationSource;
for (let affirmation of affirmations) {
if (affirmation.affirmationDayDate !== undefined) {
affirmationDate = (JSON.stringify(affirmation.affirmationDayDate)).substring(6, 11);
};
if ( affirmationDate === matchDate) {
dailyAffirmation = affirmation.id
dailyAffirmationSource = `./affirmation-images/${dailyAffirmation}.png`;
affirmationAlt = affirmation.affirmation;
affirmationTitle = affirmation.graphicsTitle;
break;
};
}
if (dailyAffirmationSource) {
affirmationSource = dailyAffirmationSource;
} else {
affirmationSource = `./affirmation-images/generic_tip_image.jpg`;
affirmationAlt = "No affirmation image available.";
affirmationTitle = "Create your own Kindspace.";
}
document.getElementById('affirmation_image').src = affirmationSource;
document.getElementById('affirmation_image').alt = affirmationAlt;
document.getElementById('affirmation_image').title = affirmationTitle;
};