2022-10-11 13:28:46 +04:00
|
|
|
function init() {
|
|
|
|
initStars()
|
|
|
|
computeAge()
|
2022-10-12 17:07:01 +04:00
|
|
|
insertSystemInfo()
|
2022-10-11 13:28:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function initStars() {
|
|
|
|
|
|
|
|
const colors = [
|
|
|
|
'#999','#9999ac','#ac9999','#acac99',
|
|
|
|
'#bbb','#bbbbcf','#cfbbbb','#cfcfbb',
|
|
|
|
'#eee','#e5e5ff','#ffe5e5','#ffffe5',
|
|
|
|
'#fff'
|
|
|
|
]
|
|
|
|
const len = colors.length
|
|
|
|
|
2022-10-12 17:07:01 +04:00
|
|
|
const canvas = document.getElementById('stars')
|
2022-10-11 13:28:46 +04:00
|
|
|
const css = getComputedStyle(canvas)
|
|
|
|
|
2022-10-12 17:07:01 +04:00
|
|
|
const w = canvas.width = styleValue(css.getPropertyValue('width'))
|
2022-10-11 13:28:46 +04:00
|
|
|
const h = canvas.height = styleValue(css.getPropertyValue('height'))
|
|
|
|
|
|
|
|
// if CSS hasn't been loaded yet
|
|
|
|
// (w and h contains NaN)
|
|
|
|
const err = [w,h].some(n => isNaN(n))
|
|
|
|
if (err) {
|
|
|
|
setTimeout(init, 200)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const ctx = canvas.getContext('2d')
|
|
|
|
const radius = 3
|
|
|
|
const circle = 2 * Math.PI
|
|
|
|
|
|
|
|
ctx.clearRect(0, 0, w, h)
|
|
|
|
for (let star = 0; star < 200; star++) {
|
|
|
|
|
|
|
|
let color = Math.floor(Math.random() * len)
|
|
|
|
ctx.fillStyle = colors[color]
|
|
|
|
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.arc(
|
|
|
|
Math.round(Math.random() * w),
|
|
|
|
Math.round(Math.random() * h),
|
|
|
|
radius, 0, circle, false
|
|
|
|
)
|
|
|
|
ctx.fill()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeAge() {
|
|
|
|
|
|
|
|
const birthday = new Date(2009, 7, 13, 12, 30)
|
|
|
|
const timedelta = Date.now() - birthday.getTime()
|
|
|
|
|
|
|
|
/*
|
|
|
|
The line below is equivalent to:
|
|
|
|
const age = timedelta / 1000 / 60 / 60 / 24 / 365.25
|
|
|
|
where:
|
|
|
|
1000: convert milliseconds -> seconds
|
|
|
|
60: secs -> minutes
|
|
|
|
60: minutes -> hours
|
|
|
|
24: hours -> days
|
|
|
|
365.25: average count of days in a year:
|
|
|
|
(366 + (365 * 3)) / 4 = 365.25
|
|
|
|
*/
|
|
|
|
const age = timedelta / (1000 * 60 * 60 * 24 * 365.25)
|
|
|
|
|
|
|
|
document.getElementById('age-js').textContent = Math.floor(age)
|
|
|
|
}
|
2022-10-12 17:07:01 +04:00
|
|
|
|
|
|
|
function insertSystemInfo() {
|
|
|
|
|
|
|
|
const inxi = document.getElementById('inxi')
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest()
|
2023-03-17 16:56:58 +04:00
|
|
|
xhr.open('GET', '/inxi.txt')
|
2022-10-12 17:07:01 +04:00
|
|
|
|
|
|
|
xhr.onreadystatechange = () => {
|
|
|
|
if (xhr.readyState != xhr.DONE) return
|
|
|
|
if (xhr.status != 200) return
|
|
|
|
inxi.textContent = xhr.response
|
|
|
|
}
|
|
|
|
|
|
|
|
xhr.send()
|
|
|
|
}
|