From c5fafb4c16cc38386931d66ef426c8ff1235177f Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 28 Jul 2019 01:27:28 +0000 Subject: [PATCH] assets/scripts.js: Allow jumping to a chapter by setting the hash --- assets/scripts.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/assets/scripts.js b/assets/scripts.js index 4b2be9a..702369e 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -382,9 +382,11 @@ window.onload = function() { } }; - if (location.hash) { - var segmentId = location.hash.slice(1); - playSegment(segmentId); + window.onhashchange = function() { + playHash(window.location.hash); + }; + if (window.location.hash) { + playHash(window.location.hash); } }; @@ -427,3 +429,14 @@ function playSegment(segmentId, noSeek) { seek(ms); } } + +function playHash(hash) { + if (hash) { + let loc = hash.slice(1).split('/'); + let segmentId = loc[0]; + if (loc.length > 1) + seek(momentsBySegment[segmentId][loc[1]].startMs); + else + seek(getSegmentMs(segmentId)); + } +}