From a2df9a69dcc14cb70118cda2ded499055e7ee358 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 21 Aug 2022 17:31:56 +0200 Subject: m. update --- app/banner.js | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 app/banner.js (limited to 'app/banner.js') diff --git a/app/banner.js b/app/banner.js new file mode 100644 index 0000000..6daa2b7 --- /dev/null +++ b/app/banner.js @@ -0,0 +1,163 @@ +// noinspection JSUnresolvedVariable + +function timeAgo(time) { + if (!isNaN(parseInt(time))) { + time = new Date(time).getTime(); + } + + let periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; + let lengths = ["60", "60", "24", "7", "4.35", "12", "100"]; + + let now = new Date().getTime(); + + let difference = Math.round((now - time) / 1000); + let tense; + let period; + + if (difference <= 10 && difference >= 0) { + return tense = "now"; + } else if (difference > 0) { + tense = "ago"; + } else { + tense = "later"; + } + + let j; + + for (j = 0; difference >= lengths[j] && j < lengths.length - 1; j++) { + difference /= lengths[j]; + } + + difference = Math.round(difference); + + period = periods[j] + (difference > 1 ? "s" : ''); + return `${difference} ${period} ${tense}`; +} + +async function refreshBanner(offline) { + if (!offline) offline = false; + + let data = window.currentMemberData; + let index; + + if (data['last_fronted'] && data['last_fronted']['timestamp']) { + data['last_fronted']['relative'] = timeAgo(currentMemberData.last_fronted.timestamp * 1000); + } + + if (data.id === "scootaloo" && new Date().getDay() % 2 === 0) { + data['relations']['marefriends'] = data['relations']['marefriends'].reverse(); + } + + if (offline) { + let images = JSON.parse(await localforage.getItem("images")); + + index = 0; + for (let species of data['species']) { + data['species'][index]["icon_offline"] = images.misc.species[species['id']]; + index++; + } + + index = 0; + for (let relation of data['relations']['marefriends']) { + data['relations']['marefriends'][index]["icon_offline"] = images.ponytown[relation['id'].split("/")[0]][relation['id'].split("/")[1]]; + index++; + } + + index = 0; + for (let relation of data['relations']['sisters']) { + data['relations']['sisters'][index]["icon_offline"] = images.ponytown[relation['id'].split("/")[0]][relation['id'].split("/")[1]]; + index++; + } + + if (data['relations']['caretakers']) { + index = 0; + for (let relation of data['relations']['caretakers']) { + data['relations']['caretakers'][index]["icon_offline"] = images.ponytown[relation['id'].split("/")[0]][relation['id'].split("/")[1]]; + index++; + } + } + + data['system']['icon_offline'] = images.misc.systems[data['system']['icon']]; + } + + document.getElementById("member-banner").innerHTML = ` + +
+
+ +
+ +
+

+ ${data['name']} +

+ +
+ ${data['badges'].map(i => i.html).join(" ")} + ${data['badges'].length === 0 ? " " : ""} +
+ +
+ + Prefix${data['prefixes'].length > 1 ? 'es' : ''}: + ${data['prefixes'].join(', ')} + + + Pronouns: + ${data['pronouns']} + + ${!data['median'] ? ` + + Last fronted: + ${data['last_fronted'] ? ` + ${data['last_fronted']['now'] ? ` + Right now
+ (started ${data['last_fronted']['relative']}) + ` : ` + ${data['last_fronted']['relative']}
+ (for ${data['last_fronted']['duration']['pretty']}) + `} + ` : "A long time ago
 "} +
+ ` : ''} + + Species: + ${data['species'].map(species => ` + ${species['name']} + `).join("")} + + + System: + ${data['system']['name']} + ${data['system']['subsystem'] ? ` +
Subsystem: ${data['system']['subsystem']['name']} + ` : data['system']['temporary'] ? '
(temporary)' : ''} +
+
+
+ + Marefriend${data['relations']['sisters'].length > 1 ? 's' : ''}: ${data['relations']['marefriends'].length > 1 ? '
' : ''} + ${data['relations']['marefriends'].map(relation => ` + ${relation['name']}`).join(`,
`)} + ${data['relations']['marefriends'].length === 0 ? '-' : ''} +
+ + Sister${data['relations']['sisters'].length > 1 ? 's' : ''}: ${data['relations']['sisters'].length > 1 ? '
' : ''} + ${data['relations']['sisters'].map(relation => ` + ${relation['name']}`).join(`,
`)} + ${data['relations']['sisters'].length === 0 ? '-' : ''} +
+ ${data['little'] ? ` + + Caretaker${data['relations']['sisters'].length > 1 ? 's' : ''}: ${data['relations']['caretakers'].length > 1 ? '
' : ''} + ${data['relations']['caretakers'].map(relation => ` + ${relation['name']}`).join(`,
`)} + ${data['relations']['caretakers'].length === 0 ? '-' : ''} +
+ ` : ''} +
+
+
+ +`; +} \ No newline at end of file -- cgit