From df7e41b61a83320cd2b2ffb9a4a45234162672af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Thu, 16 Dec 2021 17:46:16 -0500 Subject: [frontend]: fix global scope, change var to let --- youtube/static/js/common.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'youtube/static/js/common.js') diff --git a/youtube/static/js/common.js b/youtube/static/js/common.js index c15921c..79f8834 100644 --- a/youtube/static/js/common.js +++ b/youtube/static/js/common.js @@ -1,16 +1,19 @@ const Q = document.querySelector.bind(document); const QA = document.querySelectorAll.bind(document); const QId = document.getElementById.bind(document); +let seconds, + minutes, + hours; function text(msg) { return document.createTextNode(msg); } function clearNode(node) { while (node.firstChild) node.removeChild(node.firstChild); } function toTimestamp(seconds) { - var seconds = Math.floor(seconds); + seconds = Math.floor(seconds); - var minutes = Math.floor(seconds/60); - var seconds = seconds % 60; + minutes = Math.floor(seconds/60); + seconds = seconds % 60; - var hours = Math.floor(minutes/60); - var minutes = minutes % 60; + hours = Math.floor(minutes/60); + minutes = minutes % 60; if (hours) { return `0${hours}:`.slice(-3) + `0${minutes}:`.slice(-3) + `0${seconds}`.slice(-2); @@ -18,8 +21,7 @@ function toTimestamp(seconds) { return `0${minutes}:`.slice(-3) + `0${seconds}`.slice(-2); } - -var cur_track_idx = 0; +let cur_track_idx = 0; function getActiveTranscriptTrackIdx() { let textTracks = QId("js-video-player").textTracks; if (!textTracks.length) return; @@ -39,7 +41,7 @@ function getDefaultTranscriptTrackIdx() { } function doXhr(url, callback=null) { - var xhr = new XMLHttpRequest(); + let xhr = new XMLHttpRequest(); xhr.open("GET", url); xhr.onload = (e) => { callback(e.currentTarget.response); @@ -50,7 +52,7 @@ function doXhr(url, callback=null) { // https://stackoverflow.com/a/30810322 function copyTextToClipboard(text) { - var textArea = document.createElement("textarea"); + let textArea = document.createElement("textarea"); // // *** This styling is an extra step which is likely not required. *** @@ -97,8 +99,8 @@ function copyTextToClipboard(text) { textArea.select(); try { - var successful = document.execCommand('copy'); - var msg = successful ? 'successful' : 'unsuccessful'; + let successful = document.execCommand('copy'); + let msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); } catch (err) { console.log('Oops, unable to copy'); -- cgit v1.2.3