api.violets-purgatory.dev/pageUpdater.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-02-08 12:30:38 -06:00
const path = require('path'),
fs = require('fs')
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
var highlightedWords = config.highlightedWords
2024-02-08 16:03:40 -06:00
function makeStars() {
var html = ""
2024-02-08 17:25:10 -06:00
for (let index = 0; index < 35; index++) {
html += `<div class="rainDrop"></div>`
2024-02-08 16:03:40 -06:00
}
html += "<style>"
2024-02-08 17:25:10 -06:00
for (let index = 0; index < 35; index++) {
2024-02-08 16:03:40 -06:00
html += `
2024-02-08 17:25:10 -06:00
.rainDrop:nth-of-type(${index + 1}) {
animation: rainAnim${index} 1s linear;
2024-02-08 16:03:40 -06:00
animation-iteration-count: infinite;
2024-02-08 17:25:10 -06:00
animation-delay: ${Math.random() * 15}s;
2024-02-08 16:03:40 -06:00
}
`
var rando = Math.random() * 100
2024-02-08 17:25:10 -06:00
html += `@keyframes rainAnim${index} {
2024-02-08 16:03:40 -06:00
0% {
top: -10vh;
right: ${rando}vw;
visibility: visible;
}
100% {
top: 110vh;
2024-02-08 17:25:10 -06:00
right: calc(${rando}vw);
2024-02-08 16:03:40 -06:00
}
}`
}
html += "</style>"
return html
}
2024-02-08 12:30:38 -06:00
function converter(html) {
var highTable = Object.keys(highlightedWords)
for (let index = 0; index < highTable.length; index++) {
var term = highTable[index];
var replacement = `<span style="color: ${highlightedWords[term]}">${term}</span>`
html = html.replaceAll(term, replacement)
}
2024-02-08 16:03:40 -06:00
html = html.replaceAll("{BG_EFFECT}", makeStars())
2024-02-08 12:30:38 -06:00
return html
}
module.exports = { middleWare: function(req, res, next) {
var filePath = req.baseUrl + req.path
if (filePath.trim() == "/") {
filePath = "/index.html"
}
filePath = path.join(__dirname, 'static', filePath || 'index.html')
var data = fs.readFileSync(filePath).toString()
if (req.path.includes("style.css")) {
res.setHeader("Content-Type", "text/css")
res.send(data)
} else {
data = converter(data)
res.send(data)
}
}
}