grgr.me

latest commits to https://grgr.me/
Log | Files | Refs

commit be0a2e2e08ffd09dbc53d4790bb367913feb3bb7
parent 9252d743e0b96d4db74bb4c21255fcb090361c10
Author: corndog <cauchyn@firemail.cc>
Date:   Mon, 10 Jun 2019 21:20:29 -0700

Handle timestamps in youtube embeds

Diffstat:
Mfilter/youtube-embed.py | 8++++++--
Min/me/index.md | 7+++----
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/filter/youtube-embed.py b/filter/youtube-embed.py @@ -15,10 +15,14 @@ for li in lists: continue elif "youtube.com" in anchor['href']: leftSide = True if len(anchor.get_text()) < 32 else False - vid = anchor['href'].split('=')[1] + vid = anchor['href'].split('v=')[1] vid = vid.split('&')[0] + if 't=' in anchor['href']: + timestamp = '?start=' + anchor['href'].split('t=')[1].split('s')[0] + else: + timestamp = '' embed_markup = (' <span class="nowrap">[<button class="embed"' - f'onclick="toggleYT(\'{vid}\')">' + f'onclick="toggleYT(\'{vid}\', \'{timestamp}\')">' f'<img class="embed{" left" if leftSide else ""}" ' 'alt="" src=' f'"https://img.youtube.com/vi/{vid}/mqdefault.jpg">' diff --git a/in/me/index.md b/in/me/index.md @@ -3,14 +3,13 @@ tags: prose ---- <script> - function toggleYT(id) { + function toggleYT(id, timestamp) { const div = document.getElementById(id); if (!div.hasChildNodes()) { - const url = "https://www.youtube.com/embed/" + id; + const url = "https://www.youtube.com/embed/" + id + timestamp; const iframe = document.createElement('iframe'); iframe.setAttribute("src", url); - iframe.setAttribute("allow", "encrypted-media"); - iframe.setAttribute("allow", "fullscreen"); + iframe.setAttribute("allow", "encrypted-media fullscreen"); iframe.setAttribute("allowfullscreen", true); div.appendChild(iframe); div.style.paddingBottom = "56.25%";