From c4b49bc19676aeb0b626bb7ef59bc68c6560200a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jan 2025 10:26:19 +0100 Subject: [PATCH] Add public/main.js --- public/main.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 public/main.js diff --git a/public/main.js b/public/main.js new file mode 100644 index 0000000..d4a031b --- /dev/null +++ b/public/main.js @@ -0,0 +1,57 @@ +var base = "https://shelter.amy.rip/"; +var options = { headers: { "Accept": "application/json" } }; + +fetch(base, options).then(r => r.json()).then(r => { + r.filter(i => i.is_dir).forEach(e => { + const card = document.createElement('div'); + card.className = 'card d-inline border-primary m-1'; + card.style.width = '20rem'; + + const cardHeader = document.createElement('div'); + cardHeader.className = 'card-header'; + + const title = document.createElement('h4'); + title.className = 'card-title'; + cardHeader.appendChild(title); + + const cardBody = document.createElement('div'); + cardBody.className = 'card-body'; + cardBody.style.height = "5rem"; + + const text = document.createElement('p'); + text.className = 'card-text'; + + const cardFooter = document.createElement('div'); + cardFooter.className = 'card-footer py-3'; + + const download = document.createElement('button'); + download.className = 'btn btn-primary'; + download.textContent = " Download"; + + download.addEventListener("click", () => { + navigator.clipboard.writeText(base + e.url.substr(2)).then(function () { + alert('Plugin link copied to clipboard!'); + }, function (err) { + console.error('Async: Could not copy text: ', err); + }); + }) + + const icon = document.createElement('i'); + icon.className = 'bi-download'; + download.prepend(icon); + + cardFooter.appendChild(download); + + cardBody.appendChild(text); + card.appendChild(cardHeader); + card.appendChild(cardBody); + card.appendChild(cardFooter); + + fetch(base + e.url + "plugin.json").then(r => r.json()).then(r => { + title.textContent = r.name; + text.textContent = r.description; + }) + + document.querySelector(".container").appendChild(card); + }); +})