Last active
February 11, 2021 08:27
-
-
Save sergedroz/6979ad3892af2f4d677ce854ef21fa55 to your computer and use it in GitHub Desktop.
Set an Emoji as a custom Favicon in JupyterLab tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set an Emoji as a custom Favicon in JupyterLab tabs | |
# Credits: | |
# David Magnotti fir the idea using Jupyter Notebooks: https://twitter.com/davidmagnotti/status/1357757614625615872?s=20 | |
# Serge Droz for the javascript pluming | |
def set_fav_icon( s ): | |
"""Set the tab favicon to an emoji or a svg file""" | |
from IPython.display import display, HTML | |
import re | |
if len(s) == 1: | |
vb = '0 0 220 220' | |
ih = '<text y=".9em" font-size="200">{}</text>'.format(s) | |
else: | |
vb = re.findall(r'viewBox\s*=[\s\'\"]+([\-\d\.\s]+)[\s\'\"]+', svg )[0] | |
ih = re.findall(r'<svg[^<]+(<.+)</svg>', svg )[0] | |
text = """<script> | |
var id = document.activeElement.parentElement['id'] | |
var y = document.querySelectorAll('[data-id=' + id + ']') | |
var x | |
for (var i = 0; i < y.length; i++) {{ | |
x = y[i].children[0].children[0] | |
x.setAttribute('viewBox','{}') | |
x.innerHTML = '{}' | |
}} | |
</script>""".format(vb,ih) | |
display(HTML(text)) | |
set_fav_icon( '🐠' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment