favicon2 #15

Merged
kleph merged 3 commits from favicon2 into master 2020-04-09 01:03:53 +02:00
5 changed files with 31 additions and 5 deletions

View file

@ -2,7 +2,7 @@ FROM python:slim
RUN pip install flask
COPY /beer/beer.py /beer.py
COPY /beer/static /static
COPY /beer/templates /templates
COPY /beer/static /static
EXPOSE 5000

View file

@ -27,9 +27,19 @@ def index(hours=None, minutes=None):
return data
@app.route('/favicon.ico')
def favicon():
""" serve the favicon """
return send_from_directory('static', 'favicon.ico')
def default_favicon():
""" serve default favicon """
return send_from_directory('static', 'clock-icon.png')
@app.route('/favicon/<mode>')
def favicon(mode):
""" serve the favicon according to the timer """
if mode == 'beer':
filename = 'beer-icon.png'
else:
filename = 'clock-icon.png'
return send_from_directory('static', filename)
def main():
""" main func """

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
beer/static/clock-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -44,8 +44,23 @@
})();
</script>
<script>
// Update the count down every 1 second
const changeFavicon = link => {
let $favicon = document.querySelector('link[rel="icon"]')
// If a <link rel="icon"> element already exists,
// change its href to the given link.
if ($favicon !== null) {
$favicon.href = link
// Otherwise, create a new element and append it to <head>.
} else {
$favicon = document.createElement("link")
$favicon.rel = "icon"
$favicon.href = link
document.head.appendChild($favicon)
}
}
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
@ -70,6 +85,7 @@ var x = setInterval(function() {
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "<blink>BEER TIME !</blink>";
changeFavicon('/favicon/beer')
}
}, 1000);
</script>