Merge pull request 'favicon2' (#15) from favicon2 into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
a51a2f8b7a
5 changed files with 31 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
16
beer/beer.py
16
beer/beer.py
|
@ -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 """
|
||||
|
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
BIN
beer/static/clock-icon.png
Normal file
BIN
beer/static/clock-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue