From 564bca966fafaec4cd6040aeaf9a8153b3f20327 Mon Sep 17 00:00:00 2001 From: Samuel Casellas Date: Mon, 6 Jan 2025 07:32:40 -0500 Subject: [PATCH] some reformatting --- assets/js/_helpers.js | 19 +++++++++---------- assets/js/comments.js | 12 +++++------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/assets/js/_helpers.js b/assets/js/_helpers.js index 8e18169e..d4952d0f 100644 --- a/assets/js/_helpers.js +++ b/assets/js/_helpers.js @@ -153,8 +153,8 @@ window.helpers = window.helpers || { return; } - if (!options.entity_name) options.entity_name = 'unknown'; - if (!options.retry_timeout) options.retry_timeout = 1000; + options.entity_name = options.entity_name || 'unknown'; + options.retry_timeout = options.retry_timeout || 1000; const retries_total = options.retries; let currentTry = 1; @@ -197,7 +197,7 @@ window.helpers = window.helpers || { storage: (function () { // access to localStorage throws exception in Tor Browser, so try is needed let localStorageIsUsable = false; - try{localStorageIsUsable = !!localStorage.setItem;}catch(e){} + try { localStorageIsUsable = !!localStorage.setItem; } catch {} if (localStorageIsUsable) { return { @@ -206,7 +206,7 @@ window.helpers = window.helpers || { if (!storageItem) return; try { return JSON.parse(decodeURIComponent(storageItem)); - } catch(e) { + } catch { // Erase non parsable value helpers.storage.remove(key); } @@ -224,14 +224,13 @@ window.helpers = window.helpers || { return { get: function (key) { const cookiePrefix = key + '='; - function findCallback(cookie) {return cookie.startsWith(cookiePrefix);} - const matchedCookie = document.cookie.split('; ').find(findCallback); + const matchedCookie = document.cookie.split('; ').find(cookie => cookie.startsWith(cookiePrefix)); if (matchedCookie) { const cookieBody = matchedCookie.replace(cookiePrefix, ''); - if (cookieBody.length === 0) return; + if (!cookieBody.length) return; try { return JSON.parse(decodeURIComponent(cookieBody)); - } catch(e) { + } catch { // Erase non parsable value helpers.storage.remove(key); } @@ -240,9 +239,9 @@ window.helpers = window.helpers || { set: function (key, value) { const cookie_data = encodeURIComponent(JSON.stringify(value)); - // Set expiration in 2 year + // Set expiration for 2 years out const date = new Date(); - date.setFullYear(date.getFullYear()+2); + date.setFullYear(date.getFullYear() + 2); document.cookie = key + '=' + cookie_data + '; expires=' + date.toGMTString(); }, diff --git a/assets/js/comments.js b/assets/js/comments.js index 35ffa96e..6c0f7c1d 100644 --- a/assets/js/comments.js +++ b/assets/js/comments.js @@ -58,7 +58,7 @@ function get_youtube_comments() { var fallback = comments.innerHTML; comments.innerHTML = spinnerHTML; - var baseUrl = video_data.base_url || '/api/v1/comments/'+ video_data.id + var baseUrl = video_data.base_url || '/api/v1/comments/' + video_data.id var url = baseUrl + '?format=html' + '&hl=' + video_data.preferences.locale + @@ -68,10 +68,6 @@ function get_youtube_comments() { url += '&ucid=' + video_data.ucid } - var onNon200 = function (xhr) { comments.innerHTML = fallback; }; - if (video_data.params.comments[1] === 'youtube') - onNon200 = function (xhr) {}; - helpers.xhr('GET', url, {retries: 5, entity_name: 'comments'}, { on200: function (response) { var commentInnerHtml = ' \ @@ -109,7 +105,9 @@ function get_youtube_comments() { comments.children[0].children[1].children[0].onclick = swap_comments; } }, - onNon200: onNon200, // declared above + onNon200: video_data.params.comments[1] === 'youtube' + ? function (xhr) {} + : function (xhr) { comments.innerHTML = fallback; }, onError: function (xhr) { comments.innerHTML = spinnerHTML; }, @@ -125,7 +123,7 @@ function get_youtube_replies(target, load_more, load_replies) { var body = target.parentNode.parentNode; var fallback = body.innerHTML; body.innerHTML = spinnerHTML; - var baseUrl = video_data.base_url || '/api/v1/comments/'+ video_data.id + var baseUrl = video_data.base_url || '/api/v1/comments/' + video_data.id var url = baseUrl + '?format=html' + '&hl=' + video_data.preferences.locale +