added dark theme + theme selector

This commit is contained in:
iou1name 2019-01-21 08:19:54 -05:00
parent 9e9fca46d1
commit ef3da61515
5 changed files with 85 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ __pycache__/
*.swo
config.py
*.txt
secret_key

29
ss.py
View File

@ -2,13 +2,26 @@
"""
The main Flask application for serving up aggregated RSS feed entries.
"""
from flask import Flask, render_template
import os
from flask import Flask, render_template, session, request
import config
import database
app = Flask(__name__)
def read_secret_key():
if os.path.exists("secret_key"):
with open("secret_key", "rb") as file:
secret_key = file.read()
else:
secret_key = os.urandom(64)
with open("secret_key", "wb") as file:
file.write(secret_key)
app.secret_key = secret_key
read_secret_key()
@app.route("/")
def index():
"""
@ -17,4 +30,18 @@ def index():
feeds = []
for feed_url in config.FEEDS:
feeds.append(database.get_feed(feed_url))
style_sheet = session.get("style_sheet", "ss.css")
return render_template("index.html", **locals())
@app.route("/set_session")
def set_session():
"""
Allows certain values to be set in the client's session.
"""
style_sheet = request.args.get("style_sheet")
if style_sheet == "ss.css":
session["style_sheet"] = "ss.css"
elif style_sheet == "ss-dark.css":
session["style_sheet"] = "ss-dark.css"
return "true"

30
static/ss-dark.css Normal file
View File

@ -0,0 +1,30 @@
body {
background-color: #111111;
color: #FAFAFA;
font-family: Tahoma, Helvetica, sans-serif;
text-align: center;
}
a:link {
text-decoration: none;
color: #004070;
}
a:hover {
color: #B44444;
}
a:visited {
color: #B44444;
}
#globalContainer {
text-align: left;
display: inline-block;
}
.date {
margin-left: 3em;
padding-right: 1em;
font-size: 0.9em;
}

14
static/ss.js Normal file
View File

@ -0,0 +1,14 @@
function load() {
sheet = document.getElementById("styleSheet").href.replace(/^.*\//, '');
select = document.getElementById("styleSheetSelector").value = sheet;
}
function swapStyleSheet() {
var sheet = document.getElementById("styleSheetSelector").value;
document.getElementById("styleSheet").setAttribute("href", "/static/" + sheet);
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {console.log(httpRequest.responseText);};
httpRequest.open("GET", set_session_url + "?style_sheet=" + sheet, true);
httpRequest.send();
}

View File

@ -2,10 +2,21 @@
<html>
<head>
<title>/ss/</title>
<link rel="stylesheet" type="text/css" href="/static/ss.css">
<link id="styleSheet" rel="stylesheet" type="text/css" href="/static/{{ style_sheet }}">
<script type="text/javascript" src="/static/ss.js"></script>
<script>
const set_session_url = '{{ url_for("set_session") }}';
</script>
<script>window.onload = load;</script>
</head>
<body>
<div>
Style sheet:
<select id="styleSheetSelector" onChange="swapStyleSheet()">
<option name="ss.css" value="ss.css">Light</option>
<option name="ss-dark.css" value="ss-dark.css">Dark</option>
</select>
</div>
<div id="globalContainer">
{% for feed in feeds %}
<div>