Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 5fb7111

Browse files
committed
added further theme functionality
1 parent 7430a85 commit 5fb7111

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

server.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express = require('express'),
22
app = express(),
33
path = require('path'),
4+
fs = require('fs'),
45
config = require('./config.json');
56

67
app.get('/index.css', (req, res) => {
@@ -14,7 +15,22 @@ app.use("/themes", express.static(path.join(__dirname, "themes/")));
1415
app.use("/algos", express.static(path.join(__dirname, "algos/")));
1516

1617
app.get('/:theme', (req, res) => {
17-
res.sendFile(path.join(__dirname, "index.html"));
18+
switch (req.params.theme) {
19+
case 'dark':
20+
{
21+
fs.readFile(path.join(__dirname, "index.html"), (err, data) => {
22+
if (err) throw err;
23+
24+
let script = "changeTheme(\"dark\");";
25+
res.send(data.toString().substring(0, data.toString().lastIndexOf('</script>')) + script +
26+
data.toString().substring(data.toString().lastIndexOf('</script>')));
27+
});
28+
}
29+
break;
30+
default:
31+
res.sendFile(path.join(__dirname, "index.html"));
32+
break;
33+
}
1834
});
1935
app.get('/', (req, res) => {
2036
res.sendFile(path.join(__dirname, "index.html"));

visualize.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function changeTheme(theme) {
2121
return -1;
2222

2323
glob_theme = theme;
24+
if (document.getElementById('theme_in')!==null)
25+
document.getElementById('theme_in').value = theme;
26+
27+
window.history.pushState(`${theme.toUpperCase()}-THEME`, 'Changed theme ... ', `/${theme}`);
2428

2529
xhtp.open("GET", "themes/" + theme + ".css");
2630
xhtp.send();

0 commit comments

Comments
 (0)