mirror of
https://github.com/iv-org/invidious.git
synced 2025-01-10 03:20:35 +05:30
some reformatting
This commit is contained in:
parent
53e8a5d62d
commit
564bca966f
@ -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();
|
||||
},
|
||||
|
@ -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 +
|
||||
|
Loading…
Reference in New Issue
Block a user