From f9461a2e79cd0be50937139eb9d0ad1a55e0578f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Tue, 15 Dec 2020 12:30:46 -0500 Subject: Migration general theme: fix query video tag --- youtube/static/js/comments.js | 2 +- youtube/static/js/common.js | 13 +++++++------ youtube/static/js/hotkeys.js | 4 ++-- youtube/static/js/sponsorblock.js | 4 ++-- youtube/static/js/transcript-table.js | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'youtube/static/js') diff --git a/youtube/static/js/comments.js b/youtube/static/js/comments.js index 845ed3e..ccf5e39 100644 --- a/youtube/static/js/comments.js +++ b/youtube/static/js/comments.js @@ -17,4 +17,4 @@ window.addEventListener('DOMContentLoaded', function() { if (e.button == 1) window.open(details.getAttribute("src")); }); }); -}); \ No newline at end of file +}); diff --git a/youtube/static/js/common.js b/youtube/static/js/common.js index 20cfddd..c15921c 100644 --- a/youtube/static/js/common.js +++ b/youtube/static/js/common.js @@ -1,5 +1,6 @@ -Q = document.querySelector.bind(document); -QA = document.querySelectorAll.bind(document); +const Q = document.querySelector.bind(document); +const QA = document.querySelectorAll.bind(document); +const QId = document.getElementById.bind(document); function text(msg) { return document.createTextNode(msg); } function clearNode(node) { while (node.firstChild) node.removeChild(node.firstChild); } function toTimestamp(seconds) { @@ -20,7 +21,7 @@ function toTimestamp(seconds) { var cur_track_idx = 0; function getActiveTranscriptTrackIdx() { - let textTracks = Q("video").textTracks; + let textTracks = QId("js-video-player").textTracks; if (!textTracks.length) return; for (let i=0; i < textTracks.length; i++) { if (textTracks[i].mode == "showing") { @@ -30,10 +31,10 @@ function getActiveTranscriptTrackIdx() { } return cur_track_idx; } -function getActiveTranscriptTrack() { return Q("video").textTracks[getActiveTranscriptTrackIdx()]; } +function getActiveTranscriptTrack() { return QId("js-video-player").textTracks[getActiveTranscriptTrackIdx()]; } function getDefaultTranscriptTrackIdx() { - let textTracks = Q("video").textTracks; + let textTracks = QId("js-video-player").textTracks; return textTracks.length - 1; } @@ -109,4 +110,4 @@ function copyTextToClipboard(text) { window.addEventListener('DOMContentLoaded', function() { cur_track_idx = getDefaultTranscriptTrackIdx(); -}); \ No newline at end of file +}); diff --git a/youtube/static/js/hotkeys.js b/youtube/static/js/hotkeys.js index e199f3b..8c08c11 100644 --- a/youtube/static/js/hotkeys.js +++ b/youtube/static/js/hotkeys.js @@ -2,7 +2,7 @@ function onKeyDown(e) { if (['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false; // console.log(e); - let v = Q("video"); + let v = QId("js-video-player"); let c = e.key.toLowerCase(); if (e.ctrlKey) return; else if (c == "k") { @@ -37,7 +37,7 @@ function onKeyDown(e) { else tt.mode = "showing"; } else if (c == "t") { - let ts = Math.floor(Q("video").currentTime); + let ts = Math.floor(QId("js-video-player").currentTime); copyTextToClipboard(`https://youtu.be/${data.video_id}?t=${ts}`); } } diff --git a/youtube/static/js/sponsorblock.js b/youtube/static/js/sponsorblock.js index dab4372..a2fd094 100644 --- a/youtube/static/js/sponsorblock.js +++ b/youtube/static/js/sponsorblock.js @@ -13,7 +13,7 @@ function load_sponsorblock(){ const info_elem = Q('#skip_n'); if (info_elem.innerText.length) return; // already fetched const hash = sha256(data.video_id).substr(0,4); - const video_obj = Q("video"); + const video_obj = QId("js-video-player"); let url = `/https://sponsor.ajay.app/api/skipSegments/${hash}`; fetch(url) .then(response => response.json()) @@ -37,4 +37,4 @@ function load_sponsorblock(){ } } }); -} \ No newline at end of file +} diff --git a/youtube/static/js/transcript-table.js b/youtube/static/js/transcript-table.js index 3f1f210..711dcb8 100644 --- a/youtube/static/js/transcript-table.js +++ b/youtube/static/js/transcript-table.js @@ -1,7 +1,7 @@ var details_tt, select_tt, table_tt; function renderCues() { - var selectedTrack = Q("video").textTracks[select_tt.selectedIndex]; + var selectedTrack = QId("js-video-player").textTracks[select_tt.selectedIndex]; let cuesList = [...selectedTrack.cues]; var is_automatic = cuesList[0].text.startsWith(" \n"); @@ -38,7 +38,7 @@ function renderCues() { a.href = "javascript:;"; // TODO: replace this with ?t parameter if (title) a.title = title; a.addEventListener("click", (e) => { - Q("video").currentTime = startTime; + QId("js-video-player").currentTime = startTime; }) return a; } @@ -92,7 +92,7 @@ function renderCues() { } function loadCues() { - let textTracks = Q("video").textTracks; + let textTracks = QId("js-video-player").textTracks; let selectedTrack = textTracks[select_tt.selectedIndex]; // See https://developer.mozilla.org/en-US/docs/Web/API/TextTrack/mode @@ -120,7 +120,7 @@ function loadCues() { } window.addEventListener('DOMContentLoaded', function() { - let textTracks = Q("video").textTracks; + let textTracks = QId("js-video-player").textTracks; if (!textTracks.length) return; details_tt = Q("details#transcript-details"); -- cgit v1.2.3