From 09bd0164ebc020a54b944b7326dcba496fb5d82c Mon Sep 17 00:00:00 2001 From: Minteck Date: Fri, 26 Aug 2022 22:29:23 +0200 Subject: idk when was the last commit so I'm making a new one - Violet Dawn --- app/banner.js | 97 ++++++++++++++++++++++++++----------- app/build.js | 15 +++++- app/demo/index.php | 3 ++ app/fronters/dl.js | 2 +- app/fronters/index.html | 6 +-- app/fronters/ponies/qbzxm.png | Bin 23979 -> 27713 bytes app/fronters/profiles/erefx.png | Bin 826530 -> 826530 bytes app/fronters/profiles/erknz.png | Bin 56915 -> 56915 bytes app/fronters/profiles/gevde.png | Bin 100880 -> 100880 bytes app/fronters/profiles/gfhsr.png | Bin 1642044 -> 1642044 bytes app/fronters/profiles/ghuln.png | Bin 370233 -> 370233 bytes app/fronters/profiles/hpwyq.png | Bin 2770 -> 2770 bytes app/fronters/profiles/jnbae.png | Bin 60223 -> 60223 bytes app/fronters/profiles/khsbb.png | Bin 249236 -> 249236 bytes app/fronters/profiles/kkhbw.png | Bin 40300 -> 40300 bytes app/fronters/profiles/kzfjn.png | Bin 0 -> 825561 bytes app/fronters/profiles/lllfw.png | Bin 973226 -> 745786 bytes app/fronters/profiles/lzlaq.png | Bin 0 -> 26543 bytes app/fronters/profiles/mglyq.png | Bin 91476 -> 91476 bytes app/fronters/profiles/mhnqy.png | Bin 27452 -> 27452 bytes app/fronters/profiles/pabmo.png | Bin 124750 -> 124750 bytes app/fronters/profiles/qbzxm.png | Bin 71995 -> 2843 bytes app/fronters/profiles/qraku.png | Bin 45898 -> 45898 bytes app/fronters/profiles/rdstg.png | Bin 16881 -> 16881 bytes app/fronters/profiles/rirgf.png | Bin 825561 -> 825561 bytes app/fronters/profiles/rpjok.png | Bin 1542918 -> 1542918 bytes app/fronters/profiles/sehke.png | Bin 1947 -> 1947 bytes app/fronters/profiles/tfbob.png | Bin 14049 -> 14049 bytes app/fronters/profiles/tmgiu.png | Bin 260760 -> 260760 bytes app/fronters/profiles/vncoa.png | Bin 46475 -> 46475 bytes app/fronters/profiles/vvsxf.png | Bin 61010 -> 61010 bytes app/fronters/profiles/xbvwt.png | Bin 70342 -> 70342 bytes app/fronters/profiles/xcjhj.png | Bin 107053 -> 107053 bytes app/fronters/profiles/zajrk.png | Bin 2097 -> 2097 bytes app/fronters/profiles/zdtsg.png | Bin 2817 -> 3046 bytes app/fronters/profiles/zhtzs.png | Bin 673763 -> 673763 bytes app/fronters/profiles/ztfjz.png | Bin 184686 -> 184686 bytes app/fronters/profiles/zzise.png | Bin 69145 -> 69145 bytes app/fronters/script.js | 12 ++--- app/index.html | 16 ++++-- app/load.js | 105 +++++++++++++++++++++++++++++----------- app/sw.js | 47 +++++++++++++++++- app/update.sh | 7 +++ 43 files changed, 239 insertions(+), 71 deletions(-) create mode 100644 app/demo/index.php create mode 100644 app/fronters/profiles/kzfjn.png create mode 100644 app/fronters/profiles/lzlaq.png create mode 100755 app/update.sh (limited to 'app') diff --git a/app/banner.js b/app/banner.js index 6daa2b7..8dd42a4 100644 --- a/app/banner.js +++ b/app/banner.js @@ -1,4 +1,5 @@ // noinspection JSUnresolvedVariable +window.bannerFrench = false; function timeAgo(time) { if (!isNaN(parseInt(time))) { @@ -6,6 +7,11 @@ function timeAgo(time) { } let periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; + + if (bannerFrench) { + periods = ["seconde", "minute", "heure", "jour", "semaine", "mois", "an", "des année"]; + } + let lengths = ["60", "60", "24", "7", "4.35", "12", "100"]; let now = new Date().getTime(); @@ -14,12 +20,22 @@ function timeAgo(time) { let tense; let period; - if (difference <= 10 && difference >= 0) { - return tense = "now"; - } else if (difference > 0) { - tense = "ago"; + if (bannerFrench) { + if (difference <= 10 && difference >= 0) { + return "à l'instant"; + } else if (difference > 0) { + tense = "il y a"; + } else { + tense = "dans"; + } } else { - tense = "later"; + if (difference <= 10 && difference >= 0) { + return "now"; + } else if (difference > 0) { + tense = "ago"; + } else { + tense = "later"; + } } let j; @@ -31,11 +47,19 @@ function timeAgo(time) { difference = Math.round(difference); period = periods[j] + (difference > 1 ? "s" : ''); - return `${difference} ${period} ${tense}`; + + if (bannerFrench) { + return `${tense} ${difference} ${period}`; + } else { + return `${difference} ${period} ${tense}`; + } } -async function refreshBanner(offline) { +async function refreshBanner(offline, french) { if (!offline) offline = false; + if (!french) french = false; + + window.bannerFrench = french; let data = window.currentMemberData; let index; @@ -84,12 +108,16 @@ async function refreshBanner(offline) {
- +

- ${data['name']} + ${data['id'] === "unknown" ? ` + Unknown member (${data['system']['name']} System) + ` : data['id'] === "fusion" ? (data['name'] === "fusion" ? ` + Multiple merged members + ` : data['name']) : data['name']}

@@ -97,65 +125,80 @@ async function refreshBanner(offline) { ${data['badges'].length === 0 ? " " : ""}
-
+
- Prefix${data['prefixes'].length > 1 ? 'es' : ''}: + ${french ? `Préfixe${data['prefixes'].length > 1 ? 's' : ''} ` : `Prefix${data['prefixes'].length > 1 ? 'es' : ''}`}: ${data['prefixes'].join(', ')} - Pronouns: - ${data['pronouns']} + ${french ? "Pronoms :" : "Pronouns:"} + ${data['id'] === "fusion" ? "she/her" : data['pronouns']} - ${!data['median'] ? ` + ${!data['median'] && data['id'] !== "unknown" ? ` - Last fronted: + ${data["id"] === "fusion" ? ` + Fronting since : ${data['last_fronted'] ? ` ${data['last_fronted']['now'] ? ` - Right now
- (started ${data['last_fronted']['relative']}) + ${data['last_fronted']['relative']}
  + ` : ` + Not fronting
  + `} + ` : `Not fronting
 `}` : ` + ${french ? "Front :" : "Last fronted:"} + ${data['last_fronted'] ? ` + ${data['last_fronted']['now'] ? ` + ${french ? "En ce moment" : "Right now"}
+ (${french ? "commencé" : "started"} ${data['last_fronted']['relative']}) ` : ` ${data['last_fronted']['relative']}
- (for ${data['last_fronted']['duration']['pretty']}) + (${french ? "pendant" : "for"} ${data['last_fronted']['duration']['pretty']}) `} - ` : "A long time ago
 "} + ` : `${french ? "Il y a très longtemps" : "A long time ago"}
 `}`}
` : ''} + ${data['id'] !== "fusion" ? ` - Species: + ${data['id'] === "unknown" ? "Species: best to ask" : ` + ${french ? (data['species'].length > 1 ? "Espèces : " : "Espèce : ") : "Species: "} ${data['species'].map(species => ` ${species['name']} - `).join("")} - + `).join("")}`} + ` : ''} + ${data['id'] !== "fusion" ? ` - System: + ${french ? "Système : " : "System: "} ${data['system']['name']} ${data['system']['subsystem'] ? ` -
Subsystem: ${data['system']['subsystem']['name']} +
${french ? "Sous-système : " : "Subsystem: "} ${data['system']['subsystem']['name']} ` : data['system']['temporary'] ? '
(temporary)' : ''}
+ ` : ''}
+ ${data['id'] !== "unknown" && data['id'] !== "fusion" ? `
- Marefriend${data['relations']['sisters'].length > 1 ? 's' : ''}: ${data['relations']['marefriends'].length > 1 ? '
' : ''} + ${french ? (data['relations']['marefriends'].length > 1 ? 'Partenaires ' : 'Partenaire ') : `Marefriend${data['relations']['marefriends'].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 ? '
' : ''} + ${french ? (data['relations']['sisters'].length > 1 ? 'Sœurs ' : 'Sœur ') : `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 ? '
' : ''} + ${french ? (data['relations']['sisters'].length > 1 ? 'Caretakers ' : 'Caretaker ') : `Caretakers${data['relations']['caretakers'].length > 1 ? 's' : ''}`}: ${data['relations']['caretakers'].length > 1 ? '
' : ''} ${data['relations']['caretakers'].map(relation => ` ${relation['name']}`).join(`,
`)} ${data['relations']['caretakers'].length === 0 ? '-' : ''}
` : ''}
+ ` : '
 
'}
diff --git a/app/build.js b/app/build.js index f31e572..9d9b8fc 100644 --- a/app/build.js +++ b/app/build.js @@ -2,7 +2,12 @@ const fs = require('fs'); let original = fs.readFileSync("./sw.src.js").toString(); let fileList = [ - "/app/" + "/app/", + "/-/demo", + "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css", + "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js", + "/assets/logo/logo.png", + "/assets/icons/right.svg" ]; function files(dir, sdir) { for (let file of fs.readdirSync(dir)) { @@ -20,7 +25,13 @@ function files(dir, sdir) { files(".", "/app"); console.log(JSON.stringify(fileList, null, 2)); +let fileList1 = fileList; -original = original.replace('[["%CacheData%"]]', JSON.stringify(fileList, null, 4)); +fileList = []; +files("../assets/uploads", "/assets/uploads"); +console.log(JSON.stringify(fileList, null, 2)); +let fileList2 = fileList; + +original = original.replace('[["%CacheData%"]]', JSON.stringify([...fileList1, ...fileList2], null, 4)); fs.writeFileSync("./sw.js", fs.readFileSync("./localforage.js") + "\n\n" + original); \ No newline at end of file diff --git a/app/demo/index.php b/app/demo/index.php new file mode 100644 index 0000000..154f099 --- /dev/null +++ b/app/demo/index.php @@ -0,0 +1,3 @@ +
@@ -219,7 +219,7 @@
- + @@ -316,7 +324,7 @@ } } - if ('serviceWorker' in navigator) { + if ('serviceWorker' in navigator && location.search !== "?nocache") { console.log("Creating service worker..."); navigator.serviceWorker.register('/app/sw.js').then(function() { return navigator.serviceWorker.ready diff --git a/app/load.js b/app/load.js index 9efff3c..9e4d3b9 100644 --- a/app/load.js +++ b/app/load.js @@ -18,73 +18,119 @@ window.connected = false; let valuesToGet = { "pluralkit-cloudburst-members": { url: "/api/data?f=ynmuc-members.json", - limited: false + limited: false, + name: "Members at Cloudburst...", }, "pluralkit-cloudburst-fronters": { url: "/api/data?f=ynmuc-fronters.json", - limited: false + limited: false, + name: "Fronters at Cloudburst...", }, "pluralkit-cloudburst-switches": { url: "/api/data?f=ynmuc-switches.json", - limited: false + limited: false, + name: "Switches at Cloudburst...", }, "pluralkit-raindrops-members": { url: "/api/data?f=gdapd-members.json", - limited: false + limited: false, + name: "Members at Raindrops...", }, "pluralkit-raindrops-fronters": { url: "/api/data?f=gdapd-fronters.json", - limited: false + limited: false, + name: "Fronters at Raindrops...", }, "pluralkit-raindrops-switches": { url: "/api/data?f=gdapd-switches.json", - limited: false + limited: false, + name: "Switches at Raindrops...", }, "peh-cloudburst-data": { url: "/api/cloudburst-data", - limited: false + limited: false, + name: "Cloudburst data...", }, "peh-raindrops-data": { url: "/api/raindrops-data", - limited: false + limited: false, + name: "Raindrops data...", }, "peh-cloudburst-banners": { url: "/api/cloudburst-banners", - limited: false + limited: false, + name: "Cloudburst banner data...", }, "peh-raindrops-banners": { url: "/api/raindrops-banners", - limited: false + limited: false, + name: "Raindrops banner data...", }, "identity": { url: "/api/me", - limited: false + limited: false, + name: "Identity...", }, "images": { url: "/api/app-images", - limited: false + limited: false, + name: "Images...", + condition: async () => { + let known = await localforage.getItem("images-refresh"); + let currentKnown; + + try { + currentKnown = btoa(Object.keys(JSON.parse(await localforage.getItem("peh-cloudburst-data")).members).join("") + Object.keys(JSON.parse(await localforage.getItem("peh-raindrops-data")).members).join("") + new Date().toDateString()); + } catch (e) { + return true; + } + + localforage.setItem("images-refresh", currentKnown); + + if (known) { + return known !== currentKnown; + } else { + return true; + } + } }, "image-me": { url: "/api/me-picture", - limited: false + limited: false, + name: "Identity avatar...", }, "bits-transactions": { url: "/bits/Application/TransactionsList/index.php", - limited: false + limited: false, + name: "Bits transactions...", }, "bits-goal": { url: "/bits/Application/GetGoal/index.php", - limited: false + limited: false, + name: "Bits goal...", }, "bits-username": { url: "/bits/Authentication/Username/index.php", - limited: false + limited: false, + name: "Bits user info...", } } let keys = Object.keys(valuesToGet); let index = 2; +window.onerror = (event, source, lineno, colno, error) => { + console.log(event, source, lineno, colno, error); + document.getElementById("loader-message").classList.add("text-danger"); + document.getElementById("loader-message").innerText = "An error occurred."; +} + +window.onunhandledrejection = (handler, event) => { + console.log(handler, event); + document.getElementById("loader-message").classList.add("text-danger"); + document.getElementById("loader-message").innerText = "An error occurred."; +} + async function getNewValue() { if (!keys[0]) { await postLoad(); @@ -92,6 +138,9 @@ async function getNewValue() { } try { + if (valuesToGet[keys[0]].condition && !(await valuesToGet[keys[0]].condition())) throw new Error(); + + document.getElementById("loader-message").innerText = valuesToGet[keys[0]].name; await localforage.setItem(keys[0], (await (await fetchPlus(valuesToGet[keys[0]]["url"], { timeout: 3000 })).text())); keys.shift(); @@ -198,21 +247,23 @@ async function postLoad() { document.getElementById("home-app-emergency").classList.add("disabled"); } - if (window.serviceWorkerRegistration.sync) { - window.serviceWorkerRegistration.sync.register('data-sync') - .catch(function(err) { - return err; - }) - .then(() => { - console.log("Scheduled background sync for the next time connection is available"); - }) - } else { - console.log("Background sync not possible on this platform"); + if (window.serviceWorkerRegistration) { + if (window.serviceWorkerRegistration.sync) { + window.serviceWorkerRegistration.sync.register('data-sync') + .catch(function(err) { + return err; + }) + .then(() => { + console.log("Scheduled background sync for the next time connection is available"); + }) + } else { + console.log("Background sync not possible on this platform"); + } } window.currentMemberData = JSON.parse(localStorage.getItem("peh-" + JSON.parse(localStorage.getItem("identity")).id + "-banners"))[JSON.parse(localStorage.getItem("pluralkit-" + JSON.parse(localStorage.getItem("identity")).id + "-fronters")).members[0].name]; - await refreshBanner(true); refreshTooltips(); + //await refreshBanner(true); refreshTooltips(); setInterval(async () => { Array.from(document.getElementsByClassName("relative-time")).forEach((el) => { diff --git a/app/sw.js b/app/sw.js index 9e4eb39..93e2403 100644 --- a/app/sw.js +++ b/app/sw.js @@ -11,7 +11,13 @@ let cacheName = 'peh-pluralponies-pwa'; let filesToCache = [ "/app/", + "/-/demo", + "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css", + "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js", + "/assets/logo/logo.png", + "/assets/icons/right.svg", "/app/apps.js", + "/app/banner.js", "/app/bits/assets/black.css", "/app/bits/assets/chart.js", "/app/bits/assets/create.js", @@ -87,7 +93,9 @@ let filesToCache = [ "/app/fronters/profiles/jnbae.png", "/app/fronters/profiles/khsbb.png", "/app/fronters/profiles/kkhbw.png", + "/app/fronters/profiles/kzfjn.png", "/app/fronters/profiles/lllfw.png", + "/app/fronters/profiles/lzlaq.png", "/app/fronters/profiles/mglyq.png", "/app/fronters/profiles/mhnqy.png", "/app/fronters/profiles/nabky.png", @@ -130,7 +138,44 @@ let filesToCache = [ "/app/logo/logo.svg", "/app/logo/maskable.png", "/app/manifest.json", - "/app/sw.js" + "/app/sw.js", + "/app/tooltip.js", + "/app/update.sh", + "/assets/uploads/cloudburst.png", + "/assets/uploads/logo.jpg", + "/assets/uploads/pt-babs.png", + "/assets/uploads/pt-blueberrycloud.png", + "/assets/uploads/pt-cloudy.png", + "/assets/uploads/pt-duskrainbow.png", + "/assets/uploads/pt-fluttershy.png", + "/assets/uploads/pt-frost.png", + "/assets/uploads/pt-fusion.png", + "/assets/uploads/pt-izzymoonbow.png", + "/assets/uploads/pt-lavender.png", + "/assets/uploads/pt-lyra.png", + "/assets/uploads/pt-mintygrape.png", + "/assets/uploads/pt-mistycloud.png", + "/assets/uploads/pt-mossystorm.png", + "/assets/uploads/pt-pipppetals.png", + "/assets/uploads/pt-plushie.png", + "/assets/uploads/pt-poseybloom.png", + "/assets/uploads/pt-scootaloo.png", + "/assets/uploads/pt-skydream.png", + "/assets/uploads/pt-smolscoots.png", + "/assets/uploads/pt-smoltwi.png", + "/assets/uploads/pt-starrynight.png", + "/assets/uploads/pt-stuffie.png", + "/assets/uploads/pt-sunnystarscout.png", + "/assets/uploads/pt-sweetiebelle.png", + "/assets/uploads/pt-sweetiebot.png", + "/assets/uploads/pt-twilight.png", + "/assets/uploads/pt-velvet.png", + "/assets/uploads/pt-violet.png", + "/assets/uploads/pt-windyleaves.png", + "/assets/uploads/pt-zipp.png", + "/assets/uploads/pt.png", + "/assets/uploads/raindrops.png", + "/assets/uploads/ss-sparkles.png" ]; self.addEventListener('install', function(e) { diff --git a/app/update.sh b/app/update.sh new file mode 100755 index 0000000..731e32a --- /dev/null +++ b/app/update.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd fronters +node dl.js + +cd .. +node build.js \ No newline at end of file -- cgit