Skip to content

Commit 3bbd709

Browse files
authored
Merge pull request #3045 from AHOHNMYC/js-lint
Js lint
2 parents a0f566f + dbb1e3f commit 3bbd709

File tree

10 files changed

+261
-245
lines changed

10 files changed

+261
-245
lines changed

assets/js/community.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
var community_data = JSON.parse(document.getElementById('community_data').innerHTML);
1+
'use strict';
2+
var community_data = JSON.parse(document.getElementById('community_data').textContent);
23

34
String.prototype.supplant = function (o) {
45
return this.replace(/{([^{}]*)}/g, function (a, b) {
56
var r = o[b];
67
return typeof r === 'string' || typeof r === 'number' ? r : a;
78
});
8-
}
9+
};
910

1011
function hide_youtube_replies(event) {
1112
var target = event.target;
1213

13-
sub_text = target.getAttribute('data-inner-text');
14-
inner_text = target.getAttribute('data-sub-text');
14+
var sub_text = target.getAttribute('data-inner-text');
15+
var inner_text = target.getAttribute('data-sub-text');
1516

16-
body = target.parentNode.parentNode.children[1];
17+
var body = target.parentNode.parentNode.children[1];
1718
body.style.display = 'none';
1819

1920
target.innerHTML = sub_text;
@@ -25,10 +26,10 @@ function hide_youtube_replies(event) {
2526
function show_youtube_replies(event) {
2627
var target = event.target;
2728

28-
sub_text = target.getAttribute('data-inner-text');
29-
inner_text = target.getAttribute('data-sub-text');
29+
var sub_text = target.getAttribute('data-inner-text');
30+
var inner_text = target.getAttribute('data-sub-text');
3031

31-
body = target.parentNode.parentNode.children[1];
32+
var body = target.parentNode.parentNode.children[1];
3233
body.style.display = '';
3334

3435
target.innerHTML = sub_text;
@@ -63,8 +64,8 @@ function get_youtube_replies(target, load_more) {
6364
xhr.open('GET', url, true);
6465

6566
xhr.onreadystatechange = function () {
66-
if (xhr.readyState == 4) {
67-
if (xhr.status == 200) {
67+
if (xhr.readyState === 4) {
68+
if (xhr.status === 200) {
6869
if (load_more) {
6970
body = body.parentNode.parentNode;
7071
body.removeChild(body.lastElementChild);
@@ -92,12 +93,12 @@ function get_youtube_replies(target, load_more) {
9293
body.innerHTML = fallback;
9394
}
9495
}
95-
}
96+
};
9697

9798
xhr.ontimeout = function () {
98-
console.log('Pulling comments failed.');
99+
console.warn('Pulling comments failed.');
99100
body.innerHTML = fallback;
100-
}
101+
};
101102

102103
xhr.send();
103104
}

assets/js/embed.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
var video_data = JSON.parse(document.getElementById('video_data').innerHTML);
1+
'use strict';
2+
var video_data = JSON.parse(document.getElementById('video_data').textContent);
23

34
function get_playlist(plid, retries) {
4-
if (retries == undefined) retries = 5;
5+
if (retries === undefined) retries = 5;
56

67
if (retries <= 0) {
7-
console.log('Failed to pull playlist');
8+
console.warn('Failed to pull playlist');
89
return;
910
}
1011

12+
var plid_url;
1113
if (plid.startsWith('RD')) {
12-
var plid_url = '/api/v1/mixes/' + plid +
14+
plid_url = '/api/v1/mixes/' + plid +
1315
'?continuation=' + video_data.id +
1416
'&format=html&hl=' + video_data.preferences.locale;
1517
} else {
16-
var plid_url = '/api/v1/playlists/' + plid +
18+
plid_url = '/api/v1/playlists/' + plid +
1719
'?index=' + video_data.index +
1820
'&continuation' + video_data.id +
1921
'&format=html&hl=' + video_data.preferences.locale;
@@ -57,17 +59,17 @@ function get_playlist(plid, retries) {
5759
}
5860
}
5961
}
60-
}
62+
};
6163

6264
xhr.onerror = function () {
63-
console.log('Pulling playlist failed... ' + retries + '/5');
64-
setTimeout(function () { get_playlist(plid, retries - 1) }, 1000);
65-
}
65+
console.warn('Pulling playlist failed... ' + retries + '/5');
66+
setTimeout(function () { get_playlist(plid, retries - 1); }, 1000);
67+
};
6668

6769
xhr.ontimeout = function () {
68-
console.log('Pulling playlist failed... ' + retries + '/5');
70+
console.warn('Pulling playlist failed... ' + retries + '/5');
6971
get_playlist(plid, retries - 1);
70-
}
72+
};
7173

7274
xhr.send();
7375
}
@@ -96,7 +98,7 @@ window.addEventListener('load', function (e) {
9698
}
9799

98100
if (video_data.video_series.length !== 0) {
99-
url.searchParams.set('playlist', video_data.video_series.join(','))
101+
url.searchParams.set('playlist', video_data.video_series.join(','));
100102
}
101103

102104
location.assign(url.pathname + url.search);

assets/js/handlers.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
});
7777

7878
n2a(document.querySelectorAll('[data-onrange="update_volume_value"]')).forEach(function (e) {
79-
var cb = function () { update_volume_value(e); }
79+
var cb = function () { update_volume_value(e); };
8080
e.oninput = cb;
8181
e.onchange = cb;
8282
});
@@ -102,13 +102,13 @@
102102
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
103103

104104
xhr.onreadystatechange = function () {
105-
if (xhr.readyState == 4) {
106-
if (xhr.status != 200) {
105+
if (xhr.readyState === 4) {
106+
if (xhr.status !== 200) {
107107
count.innerText = parseInt(count.innerText) + 1;
108108
row.style.display = '';
109109
}
110110
}
111-
}
111+
};
112112

113113
var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value;
114114
xhr.send('csrf_token=' + csrf_token);
@@ -131,35 +131,35 @@
131131
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
132132

133133
xhr.onreadystatechange = function () {
134-
if (xhr.readyState == 4) {
135-
if (xhr.status != 200) {
134+
if (xhr.readyState === 4) {
135+
if (xhr.status !== 200) {
136136
count.innerText = parseInt(count.innerText) + 1;
137137
row.style.display = '';
138138
}
139139
}
140-
}
140+
};
141141

142142
var csrf_token = target.parentNode.querySelector('input[name="csrf_token"]').value;
143143
xhr.send('csrf_token=' + csrf_token);
144144
}
145145

146146
// Handle keypresses
147-
window.addEventListener('keydown', (event) => {
147+
window.addEventListener('keydown', function (event) {
148148
// Ignore modifier keys
149149
if (event.ctrlKey || event.metaKey) return;
150150

151151
// Ignore shortcuts if any text input is focused
152152
let focused_tag = document.activeElement.tagName.toLowerCase();
153153
const allowed = /^(button|checkbox|file|radio|submit)$/;
154154

155-
if (focused_tag === "textarea") return;
156-
if (focused_tag === "input") {
155+
if (focused_tag === 'textarea') return;
156+
if (focused_tag === 'input') {
157157
let focused_type = document.activeElement.type.toLowerCase();
158158
if (!focused_type.match(allowed)) return;
159159
}
160160

161161
// Focus search bar on '/'
162-
if (event.key == "/") {
162+
if (event.key === '/') {
163163
document.getElementById('searchbox').focus();
164164
event.preventDefault();
165165
}

assets/js/notifications.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
var notification_data = JSON.parse(document.getElementById('notification_data').innerHTML);
1+
'use strict';
2+
var notification_data = JSON.parse(document.getElementById('notification_data').textContent);
23

34
var notifications, delivered;
45

56
function get_subscriptions(callback, retries) {
6-
if (retries == undefined) retries = 5;
7+
if (retries === undefined) retries = 5;
78

89
if (retries <= 0) {
910
return;
@@ -17,21 +18,21 @@ function get_subscriptions(callback, retries) {
1718
xhr.onreadystatechange = function () {
1819
if (xhr.readyState === 4) {
1920
if (xhr.status === 200) {
20-
subscriptions = xhr.response;
21+
var subscriptions = xhr.response;
2122
callback(subscriptions);
2223
}
2324
}
24-
}
25+
};
2526

2627
xhr.onerror = function () {
27-
console.log('Pulling subscriptions failed... ' + retries + '/5');
28-
setTimeout(function () { get_subscriptions(callback, retries - 1) }, 1000);
29-
}
28+
console.warn('Pulling subscriptions failed... ' + retries + '/5');
29+
setTimeout(function () { get_subscriptions(callback, retries - 1); }, 1000);
30+
};
3031

3132
xhr.ontimeout = function () {
32-
console.log('Pulling subscriptions failed... ' + retries + '/5');
33+
console.warn('Pulling subscriptions failed... ' + retries + '/5');
3334
get_subscriptions(callback, retries - 1);
34-
}
35+
};
3536

3637
xhr.send();
3738
}
@@ -40,7 +41,7 @@ function create_notification_stream(subscriptions) {
4041
notifications = new SSE(
4142
'/api/v1/auth/notifications?fields=videoId,title,author,authorId,publishedText,published,authorThumbnails,liveNow', {
4243
withCredentials: true,
43-
payload: 'topics=' + subscriptions.map(function (subscription) { return subscription.authorId }).join(','),
44+
payload: 'topics=' + subscriptions.map(function (subscription) { return subscription.authorId; }).join(','),
4445
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
4546
});
4647
delivered = [];
@@ -53,7 +54,7 @@ function create_notification_stream(subscriptions) {
5354
}
5455

5556
var notification = JSON.parse(event.data);
56-
console.log('Got notification:', notification);
57+
console.info('Got notification:', notification);
5758

5859
if (start_time < notification.published && !delivered.includes(notification.videoId)) {
5960
if (Notification.permission === 'granted') {
@@ -67,7 +68,7 @@ function create_notification_stream(subscriptions) {
6768

6869
system_notification.onclick = function (event) {
6970
window.open('/watch?v=' + event.currentTarget.tag, '_blank');
70-
}
71+
};
7172
}
7273

7374
delivered.push(notification.videoId);
@@ -82,16 +83,16 @@ function create_notification_stream(subscriptions) {
8283
'<i class="icon ion-ios-notifications-outline"></i>';
8384
}
8485
}
85-
}
86+
};
8687

8788
notifications.addEventListener('error', handle_notification_error);
8889
notifications.stream();
8990
}
9091

9192
function handle_notification_error(event) {
92-
console.log('Something went wrong with notifications, trying to reconnect...');
93+
console.warn('Something went wrong with notifications, trying to reconnect...');
9394
notifications = { close: function () { } };
94-
setTimeout(function () { get_subscriptions(create_notification_stream) }, 1000);
95+
setTimeout(function () { get_subscriptions(create_notification_stream); }, 1000);
9596
}
9697

9798
window.addEventListener('load', function (e) {

0 commit comments

Comments
 (0)