qwe/src/view.js
2024-12-11 19:21:57 -07:00

81 lines
1.6 KiB
JavaScript

import * as tags from './tags.js'
import * as note from './note.js'
import * as list from './list.js'
const app = window.app
export function Init() {
app.main = document.getElementById('main')
app.nextNote = document.getElementById('next-note')
app.prevNote = document.getElementById('prev-note')
app.streak = document.getElementById('streak')
app.title = document.getElementById('title')
}
export function Title(sTitle) {
let t = sTitle
switch(sTitle) {
case list.pageHash:
t = 'All Notes'
break
case tags.pageHash:
t = 'All Tags'
break
}
document.title = t
app.title.innerText = t
}
export function Streak() {
let consDays = 0
let pd
for(let n of app.all.keys()) {
let d = new Date(n)
if(pd && pd - d > (24 * 60 * 60 * 1000)) {
break
}
consDays++
pd = d
}
app.streak.innerText = intToRoman(consDays)
}
const numerals = [
[ 'M', 1000 ],
[ 'CM', 900 ],
[ 'D', 500 ],
[ 'CD', 400 ],
[ 'C', 100 ],
[ 'XC', 90 ],
[ 'L', 50 ],
[ 'XL', 40 ],
[ 'X', 10 ],
[ 'IX', 9 ],
[ 'V', 5 ],
[ 'IV', 4 ],
[ 'I', 1 ]
]
/**
* @param {number} num
* @return {string}
*/
const intToRoman = function(num) {
let roman = ''
while(num !== 0) {
for(let [ numeral, value ] of numerals) {
if((num - value) >= 0) {
roman += numeral
num -= value
break
}
}
}
return roman
}