diff options
author | Jesús <heckyel@hyperbola.info> | 2021-12-16 17:46:16 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-12-16 17:46:16 -0500 |
commit | df7e41b61a83320cd2b2ffb9a4a45234162672af (patch) | |
tree | d16e3b953fda8b10618478d793dd0096d98b8c35 /youtube/static/js/common.js | |
parent | dd498e63d96c5b4465e3f7c65f81433aa28f2f10 (diff) | |
download | yt-local-df7e41b61a83320cd2b2ffb9a4a45234162672af.tar.lz yt-local-df7e41b61a83320cd2b2ffb9a4a45234162672af.tar.xz yt-local-df7e41b61a83320cd2b2ffb9a4a45234162672af.zip |
[frontend]: fix global scope, change var to let
Diffstat (limited to 'youtube/static/js/common.js')
-rw-r--r-- | youtube/static/js/common.js | 24 |
1 files changed, 13 insertions, 11 deletions
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'); |