1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-11-22 17:50:11 +01:00
blowfish/site/scripts.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

async function init() {
const response = await fetch('/api/github')
const release = await response.json()
replaceDom(release)
}
window.addEventListener('load', () => init())
2020-02-26 23:28:34 +01:00
function replaceDom(release) {
if (!release) return
const releaseTagElement = document.querySelector('.release__tag')
const releaseDateElement = document.querySelector('.release__date')
const downloadsElement = document.querySelector('.downloads')
const dateFormatted = new Date(release.published_at).toLocaleDateString()
releaseTagElement.innerHTML = release.tag_name
releaseDateElement.innerHTML = `on ${dateFormatted}`
2020-02-26 23:28:34 +01:00
downloadsElement.innerHTML = ''
const isMac = navigator.userAgent.includes('Mac OS')
const isWin = navigator.userAgent.includes('Windows')
const isLinux = navigator.userAgent.includes('Linux')
2020-03-11 04:08:32 +01:00
const downloadAll = release.downloads.map(download => {
const isTargetOs =
isMac & download.name.includes('mac') ||
isWin & download.name.includes('Windows') ||
isLinux & download.name.includes('Linux')
2020-02-26 23:28:34 +01:00
const li = document.createElement('li')
const a = document.createElement('a')
a.href = download.url
if (isTargetOs) {
a.className = 'button'
a.innerHTML = `Download <span>${download.name}</span>`
} else {
a.appendChild(document.createTextNode(download.name))
}
li.appendChild(a)
return li
2020-02-26 23:28:34 +01:00
})
const downloadMain = downloadAll.filter(
link => link.querySelector('a').className === 'button'
)
const downloadSecondary = downloadAll.filter(
link => link.querySelector('a').className !== 'button'
)
2020-02-26 23:28:34 +01:00
downloadsElement.append(downloadMain[0])
downloadSecondary.forEach(download => downloadsElement.append(download))
}