diff --git a/.eslintrc.js b/.eslintrc.js index ae7cb4af..db58708a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,6 +33,7 @@ module.exports = { }, ], 'no-continue': 'off', + curly: ['error', 'all'], }, ignorePatterns: ['postcss.config.js'], plugins: ['jest'], diff --git a/assets/chat/js/autocomplete.js b/assets/chat/js/autocomplete.js index 53c59e32..1dcb0360 100644 --- a/assets/chat/js/autocomplete.js +++ b/assets/chat/js/autocomplete.js @@ -11,19 +11,27 @@ function getBucketId(id) { } function sortResults(a, b) { - if (!a || !b) return 0; + if (!a || !b) { + return 0; + } // order emotes second - if (a.isemote !== b.isemote) return a.isemote && !b.isemote ? -1 : 1; + if (a.isemote !== b.isemote) { + return a.isemote && !b.isemote ? -1 : 1; + } // order according to recency third - if (a.weight !== b.weight) return a.weight > b.weight ? -1 : 1; + if (a.weight !== b.weight) { + return a.weight > b.weight ? -1 : 1; + } // order lexically fourth const lowerA = a.data.toLowerCase(); const lowerB = b.data.toLowerCase(); - if (lowerA === lowerB) return 0; + if (lowerA === lowerB) { + return 0; + } return lowerA > lowerB ? 1 : -1; } @@ -34,9 +42,13 @@ function buildSearchCriteria(str, offset) { const endCaret = post.indexOf(' '); let useronly = false; - if (startCaret > 0) pre = pre.substring(startCaret); + if (startCaret > 0) { + pre = pre.substring(startCaret); + } - if (endCaret > -1) post = post.substring(0, endCaret); + if (endCaret > -1) { + post = post.substring(0, endCaret); + } // Ignore the first char as part of the search and flag as a user only search if (pre.lastIndexOf('@') === 0 || pre.lastIndexOf('>') === 0) { @@ -55,13 +67,17 @@ function buildSearchCriteria(str, offset) { }; } function timeoutHelpers(ac) { - if (suggestTimeoutId) clearTimeout(suggestTimeoutId); + if (suggestTimeoutId) { + clearTimeout(suggestTimeoutId); + } suggestTimeoutId = setTimeout(() => ac.reset(), 15000, ac); } function updateHelpers(ac) { ac.chat.ui.toggleClass('chat-autocomplete-in', ac.results.length > 0); ac.ui.toggleClass('active', ac.results.length > 0); - if (ac.selected === -1) ac.container.css('left', 0); + if (ac.selected === -1) { + ac.container.css('left', 0); + } } function selectHelper(ac) { // Positioning @@ -140,10 +156,11 @@ class ChatAutoComplete { originval = this.input.val().toString(); const keycode = getKeyCode(e); if (keycode === KEYCODES.TAB) { - if (this.results.length > 0) + if (this.results.length > 0) { this.select( this.selected >= this.results.length - 1 ? 0 : this.selected + 1, ); + } e.preventDefault(); e.stopPropagation(); } else if (shiftdown !== e.shiftKey && this.criteria !== null) { @@ -180,7 +197,9 @@ class ChatAutoComplete { const keycode = getKeyCode(e); if (keycode !== KEYCODES.TAB && keycode !== KEYCODES.ENTER) { const str = this.input.val().toString(); - if (str.trim().length === 0) this.reset(); + if (str.trim().length === 0) { + this.reset(); + } // If a key WAS pressed, but keypress event did not fire // Check if the value changed between the key down, and key up // Keys like `backspace` @@ -266,7 +285,9 @@ class ChatAutoComplete { select(index) { this.selected = Math.min(index, this.results.length - 1); const result = this.results[this.selected]; - if (!result) return; + if (!result) { + return; + } const pre = this.criteria.orig.substr(0, this.criteria.startCaret); let post = this.criteria.orig.substr( @@ -275,7 +296,9 @@ class ChatAutoComplete { // always add a space after our completion if there isn't one since people // would usually add one anyway - if (post[0] !== ' ' || post.length === 0) post = ` ${post}`; + if (post[0] !== ' ' || post.length === 0) { + post = ` ${post}`; + } this.input.focus().val(pre + result.data + post); // Move the caret to the end of the replacement string + 1 for the space diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index b0e669c8..88a025d6 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -458,8 +458,11 @@ class Chat { 100, () => { this.ishidden = (document.visibilityState || 'visible') !== 'visible'; - if (!this.ishidden) this.focusIfNothingSelected(); - else ChatMenu.closeMenus(this); + if (!this.ishidden) { + this.focusIfNothingSelected(); + } else { + ChatMenu.closeMenus(this); + } }, { atBegin: false }, ), @@ -672,7 +675,9 @@ class Chat { // Save settings if save=true then apply current settings to chat applySettings(save = true) { - if (save) this.saveSettings(); + if (save) { + this.saveSettings(); + } // Formats DATE_FORMATS.TIME = this.settings.get('timestampformat'); @@ -725,7 +730,9 @@ class Chat { } addUser(data) { - if (!data) return null; + if (!data) { + return null; + } const normalized = data.nick.toLowerCase(); let user = this.users.get(normalized); if (!user) { @@ -755,8 +762,10 @@ class Chat { } addMessage(message, win = null) { - // eslint-disable-next-line no-param-reassign - if (win === null) win = this.mainwindow; + if (win === null) { + // eslint-disable-next-line no-param-reassign + win = this.mainwindow; + } // Break the current combo if this message is not an emote // We don't need to check what type the current message is, we just know that its a new message, so the combo is invalid. @@ -764,8 +773,9 @@ class Chat { win.lastmessage && win.lastmessage.type === MessageTypes.EMOTE && win.lastmessage.emotecount > 1 - ) + ) { win.lastmessage.completeCombo(); + } // Populate the tag and mentioned users for this $message. if ( @@ -855,7 +865,9 @@ class Chat { const win = this.windows.get(name); if (win !== null && win !== this.getActiveWindow()) { this.windows.forEach((w) => { - if (w.visible) w.hide(); + if (w.visible) { + w.hide(); + } }); win.show(); win.update(); @@ -927,7 +939,9 @@ class Chat { this.windowselect.toggle(this.windows.size > 1); - if (this.mainwindow !== null) this.mainwindow.update(); + if (this.mainwindow !== null) { + this.mainwindow.update(); + } } getActiveMenu() { @@ -1054,19 +1068,25 @@ class Chat { users.push(this.addUser(data.recipient)); } users.forEach((u) => { - if (this.ignored(u.username)) return; + if (this.ignored(u.username)) { + return; + } this.autocomplete.add(u.displayName, false, Date.now()); }); } } onCLOSE(retryMilli) { - if (this.chatpoll.isPollStarted()) this.chatpoll.endPoll(); // end poll on disconnect so it is not there forever. - if (retryMilli > 0) + if (this.chatpoll.isPollStarted()) { + this.chatpoll.endPoll(); + } // end poll on disconnect so it is not there forever. + if (retryMilli > 0) { MessageBuilder.error( `Disconnected, retry in ${Math.round(retryMilli / 1000)} seconds ...`, ).into(this); - else MessageBuilder.error(`Disconnected.`).into(this); + } else { + MessageBuilder.error(`Disconnected.`).into(this); + } } onCONNECTING(url) { @@ -1115,9 +1135,13 @@ class Chat { } onPIN(msg) { - if (this.pinnedMessage?.uuid === msg.uuid) return; + if (this.pinnedMessage?.uuid === msg.uuid) { + return; + } this.pinnedMessage?.unpin(); - if (!msg.data) return; + if (!msg.data) { + return; + } const usr = this.users.get(msg.nick.toLowerCase()) ?? new ChatUser(msg); this.pinnedMessage = MessageBuilder.pinned( @@ -1144,7 +1168,9 @@ class Chat { const win = this.mainwindow; const message = MessageBuilder.message(data.data, usr, data.timestamp); - if (win.containsMessage(message)) return; + if (win.containsMessage(message)) { + return; + } const isCombo = this.emoteService.canUserUseEmote(usr, textonly) && @@ -1451,12 +1477,13 @@ class Chat { onPRIVMSG(data) { const normalized = data.nick.toLowerCase(); if (!this.ignored(normalized, data.data)) { - if (!this.whispers.has(normalized)) + if (!this.whispers.has(normalized)) { this.whispers.set(normalized, { nick: data.nick, unread: 0, open: false, }); + } const conv = this.whispers.get(normalized); const user = this.users.get(normalized) || new ChatUser(data.nick); @@ -1464,7 +1491,7 @@ class Chat { ? data.messageid : null; - if (this.settings.get('showhispersinchat')) + if (this.settings.get('showhispersinchat')) { MessageBuilder.whisper( data.data, user, @@ -1472,20 +1499,23 @@ class Chat { data.timestamp, messageid, ).into(this); - if (this.settings.get('notificationwhisper') && this.ishidden) + } + if (this.settings.get('notificationwhisper') && this.ishidden) { this.showNotification( `${data.nick} whispered ...`, data.data, data.timestamp, this.settings.get('notificationtimeout'), ); + } const win = this.getWindow(normalized); - if (win) + if (win) { MessageBuilder.historical(data.data, user, data.timestamp).into( this, win, ); + } if (win === this.getActiveWindow()) { fetch(`${this.config.api.base}/api/messages/msg/${messageid}/open`, { credentials: 'include', @@ -1610,11 +1640,15 @@ class Chat { onEVENTSELECTED() { // Hide full pinned message interface to make everything look nice - if (this.pinnedMessage) this.pinnedMessage.hidden = true; + if (this.pinnedMessage) { + this.pinnedMessage.hidden = true; + } } onEVENTUNSELECTED() { - if (this.pinnedMessage) this.pinnedMessage.hidden = false; + if (this.pinnedMessage) { + this.pinnedMessage.hidden = false; + } } cmdSHOWPOLL() { @@ -1744,7 +1778,9 @@ class Chat { validUsernames.forEach((username) => { this.ignore(username, true); const user = this.users.get(username); - if (user) this.autocomplete.remove(user.displayName, true); + if (user) { + this.autocomplete.remove(user.displayName, true); + } }); const resultArray = Array.from(validUsernames.values()); const resultMessage = @@ -1776,7 +1812,9 @@ class Chat { validUsernames.forEach((username) => { this.ignore(username, false); const user = this.users.get(username); - if (user) this.autocomplete.add(user.displayName, false, Date.now()); + if (user) { + this.autocomplete.add(user.displayName, false, Date.now()); + } }); const haveOrHas = parts.length === 1 ? 'has' : 'have'; MessageBuilder.status( @@ -1837,8 +1875,11 @@ class Chat { nick: parts[0], reason: parts.slice(2, parts.length).join(' '), }; - if (/^perm/i.test(parts[1])) payload.ispermanent = true; - else payload.duration = this.parseTimeInterval(parts[1]); + if (/^perm/i.test(parts[1])) { + payload.ispermanent = true; + } else { + payload.duration = this.parseTimeInterval(parts[1]); + } payload.banip = command === 'IPBAN'; @@ -1888,11 +1929,13 @@ class Chat { cmdHIGHLIGHT(parts, command) { const highlights = this.settings.get('highlightnicks'); if (parts.length === 0) { - if (highlights.length > 0) + if (highlights.length > 0) { MessageBuilder.info( `Currently highlighted users: ${highlights.join(',')}.`, ).into(this); - else MessageBuilder.info(`No highlighted users.`).into(this); + } else { + MessageBuilder.info(`No highlighted users.`).into(this); + } return; } if (!nickregex.test(parts[0])) { @@ -1902,11 +1945,15 @@ class Chat { const i = highlights.indexOf(nick); switch (command) { case 'UNHIGHLIGHT': - if (i !== -1) highlights.splice(i, 1); + if (i !== -1) { + highlights.splice(i, 1); + } break; case 'HIGHLIGHT': default: - if (i === -1) highlights.push(nick); + if (i === -1) { + highlights.push(nick); + } break; } MessageBuilder.info( @@ -2177,12 +2224,13 @@ class Chat { if (win !== (null || undefined)) { this.windowToFront(normalized); } else { - if (!this.whispers.has(normalized)) + if (!this.whispers.has(normalized)) { this.whispers.set(normalized, { nick: normalized, unread: 0, open: false, }); + } this.openConversation(normalized); } } else { @@ -2287,7 +2335,9 @@ class Chat { parts[1] = parts[0]; parts[0] = this.user.username; } - if (!parts[0]) parts[0] = this.user.username; + if (!parts[0]) { + parts[0] = this.user.username; + } if (!parts[0] || !nickregex.test(parts[0].toLowerCase())) { MessageBuilder.error('Invalid nick - /mentions ').into( this, @@ -2605,7 +2655,9 @@ class Chat { icon: '/notifyicon.png?v2', dir: 'auto', }); - if (timeout) setTimeout(() => n.close(), 8000); + if (timeout) { + setTimeout(() => n.close(), 8000); + } } } @@ -2633,7 +2685,9 @@ class Chat { const url = window.location || window.location.href || null; const regex = new RegExp(`[?&]${sanitizedName}(=([^&#]*)|&|#|$)`); const results = regex.exec(url); - if (!results || !results[2]) return null; + if (!results || !results[2]) { + return null; + } return decodeURIComponent(results[2].replace(/\+/g, ' ')); } diff --git a/assets/chat/js/emotes.js b/assets/chat/js/emotes.js index 32da01a0..937066e9 100644 --- a/assets/chat/js/emotes.js +++ b/assets/chat/js/emotes.js @@ -16,7 +16,9 @@ export default class EmoteService { } emotesForUser(user) { - if (user.isPrivileged()) return this.emotes; + if (user.isPrivileged()) { + return this.emotes; + } let emotes = this.emotes.filter( (e) => e.minimumSubTier <= user.subTier && !e.twitch, diff --git a/assets/chat/js/event-bar/EventBarEvent.js b/assets/chat/js/event-bar/EventBarEvent.js index fdf14a84..069f0640 100644 --- a/assets/chat/js/event-bar/EventBarEvent.js +++ b/assets/chat/js/event-bar/EventBarEvent.js @@ -54,8 +54,12 @@ export default class EventBarEvent extends EventEmitter { chat.flairs, ); - if (tierColor) eventTemplate.style.borderColor = tierColor; - if (rainbowColor) eventTemplate.classList.add('rainbow-border'); + if (tierColor) { + eventTemplate.style.borderColor = tierColor; + } + if (rainbowColor) { + eventTemplate.classList.add('rainbow-border'); + } break; } case MessageTypes.DONATION: { diff --git a/assets/chat/js/focus.js b/assets/chat/js/focus.js index 9330c16a..e7345075 100644 --- a/assets/chat/js/focus.js +++ b/assets/chat/js/focus.js @@ -17,8 +17,9 @@ class ChatUserFocus { toggleElement(target) { const t = $(target); if (t.hasClass('chat-user')) { - if (!this.chat.settings.get('focusmentioned')) + if (!this.chat.settings.get('focusmentioned')) { this.toggleFocus(t.closest('.msg-user').data('username'), false, true); + } this.toggleFocus(t.text()); } else if (t.hasClass('user') && !t.hasClass('tier')) { this.toggleFocus(t.text()); diff --git a/assets/chat/js/formatters/EmbedUrlFormatter.js b/assets/chat/js/formatters/EmbedUrlFormatter.js index 78e907d0..00421076 100644 --- a/assets/chat/js/formatters/EmbedUrlFormatter.js +++ b/assets/chat/js/formatters/EmbedUrlFormatter.js @@ -9,9 +9,13 @@ export default class EmbedUrlFormatter { const target = chat.isBigscreenEmbed() ? '_top' : '_blank'; let extraclass = ''; - if (/\b(?:NSFL)\b/i.test(str)) extraclass = 'nsfl-link'; - else if (/\b(?:NSFW)\b/i.test(str)) extraclass = 'nsfw-link'; - else if (/\b(?:SPOILERS)\b/i.test(str)) extraclass = 'spoilers-link'; + if (/\b(?:NSFL)\b/i.test(str)) { + extraclass = 'nsfl-link'; + } else if (/\b(?:NSFW)\b/i.test(str)) { + extraclass = 'nsfw-link'; + } else if (/\b(?:SPOILERS)\b/i.test(str)) { + extraclass = 'spoilers-link'; + } const baseUrl = chat.config.dggOrigin + chat.bigscreenPath; return str.replace( diff --git a/assets/chat/js/formatters/UrlFormatter.js b/assets/chat/js/formatters/UrlFormatter.js index e103c9f2..1aac16bd 100644 --- a/assets/chat/js/formatters/UrlFormatter.js +++ b/assets/chat/js/formatters/UrlFormatter.js @@ -10,13 +10,19 @@ export default class UrlFormatter { } format(chat, str) { - if (!str) return undefined; + if (!str) { + return undefined; + } const self = this; let extraclass = ''; - if (/\b(?:NSFL)\b/i.test(str)) extraclass = 'nsfl-link'; - else if (/\b(?:NSFW)\b/i.test(str)) extraclass = 'nsfw-link'; - else if (/\b(?:SPOILERS)\b/i.test(str)) extraclass = 'spoilers-link'; + if (/\b(?:NSFL)\b/i.test(str)) { + extraclass = 'nsfl-link'; + } else if (/\b(?:NSFW)\b/i.test(str)) { + extraclass = 'nsfw-link'; + } else if (/\b(?:SPOILERS)\b/i.test(str)) { + extraclass = 'spoilers-link'; + } return str.replace(linkregex, (url, scheme) => { const decodedUrl = self.elem.html(url).text(); diff --git a/assets/chat/js/history.js b/assets/chat/js/history.js index 559fad16..316b463d 100644 --- a/assets/chat/js/history.js +++ b/assets/chat/js/history.js @@ -37,11 +37,14 @@ class ChatInputHistory { // store the typed in message so that we can go back to it this.lastinput = this.input.val().toString(); - if (this.index <= 0) + if (this.index <= 0) { // nothing in the history, bail out return; + } // down arrow, but nothing to show - } else return; + } else { + return; + } } const index = this.index + direction; @@ -66,12 +69,14 @@ class ChatInputHistory { if ( this.history.length > 0 && this.history[this.history.length - 1] === message - ) + ) { return; + } this.history.push(message); // limit entries - if (this.history.length > this.maxentries) + if (this.history.length > this.maxentries) { this.history.splice(0, this.history.length - this.maxentries); + } ChatStore.write('chat.history', this.history); } } diff --git a/assets/chat/js/menus/ChatEmoteMenu.js b/assets/chat/js/menus/ChatEmoteMenu.js index 7f01df9d..1240e4c3 100644 --- a/assets/chat/js/menus/ChatEmoteMenu.js +++ b/assets/chat/js/menus/ChatEmoteMenu.js @@ -43,7 +43,9 @@ export default class ChatEmoteMenu extends ChatMenu { this.chat.emoteService.tiers.forEach((tier) => { const emotes = this.chat.emoteService.emotePrefixesForTier(tier); - if (!emotes.length) return; + if (!emotes.length) { + return; + } const title = tier === 0 ? 'All Users' : `Tier ${tier} Subscribers`; const locked = diff --git a/assets/chat/js/menus/ChatMenu.js b/assets/chat/js/menus/ChatMenu.js index b079dd97..1784e5e3 100644 --- a/assets/chat/js/menus/ChatMenu.js +++ b/assets/chat/js/menus/ChatMenu.js @@ -14,7 +14,9 @@ export default class ChatMenu extends EventEmitter { }); this.ui.on('click', '.close,.chat-menu-close', this.hide.bind(this)); this.btn.on('click', (e) => { - if (this.visible) chat.input.focus(); + if (this.visible) { + chat.input.focus(); + } this.toggle(e); return false; }); @@ -43,11 +45,15 @@ export default class ChatMenu extends EventEmitter { toggle() { const wasVisible = this.visible; ChatMenu.closeMenus(this.chat); - if (!wasVisible) this.show(); + if (!wasVisible) { + this.show(); + } } redraw() { - if (this.visible && this.scrollplugin) this.scrollplugin.reset(); + if (this.visible && this.scrollplugin) { + this.scrollplugin.reset(); + } } static closeMenus(chat) { diff --git a/assets/chat/js/menus/ChatSettingsMenu.js b/assets/chat/js/menus/ChatSettingsMenu.js index d9052f92..fa956c64 100644 --- a/assets/chat/js/menus/ChatSettingsMenu.js +++ b/assets/chat/js/menus/ChatSettingsMenu.js @@ -37,16 +37,18 @@ export default class ChatSettingsMenu extends ChatMenu { if (val !== undefined) { switch (name) { case 'profilesettings': - if (!val && this.chat.authenticated) + if (!val && this.chat.authenticated) { fetch(`${this.chat.config.api.base}/api/chat/me/settings`, { credentials: 'include', method: 'DELETE', }).catch(); + } break; case 'notificationwhisper': case 'notificationhighlight': - if (val) + if (val) { this.notificationPermission().then(() => this.updateNotification()); + } break; default: break; diff --git a/assets/chat/js/menus/ChatUserInfoMenu.js b/assets/chat/js/menus/ChatUserInfoMenu.js index d97f366c..ccb7fe34 100644 --- a/assets/chat/js/menus/ChatUserInfoMenu.js +++ b/assets/chat/js/menus/ChatUserInfoMenu.js @@ -45,7 +45,9 @@ export default class ChatUserInfoMenu extends ChatMenuFloating { this.chat.output.on('contextmenu', '.msg-chat .user', (e) => { // If the target has this class, it's a sub tier label styled to match the // username color of the sub (which requires the `user` class). - if (e.currentTarget.classList.contains('tier')) return false; + if (e.currentTarget.classList.contains('tier')) { + return false; + } const message = $(e.currentTarget).closest('.msg-chat'); this.showUser(e, message); @@ -104,12 +106,13 @@ export default class ChatUserInfoMenu extends ChatMenuFloating { if (win) { this.chat.windowToFront(this.clickedNick); } else { - if (!this.chat.whispers.has(this.clickedNick)) + if (!this.chat.whispers.has(this.clickedNick)) { this.chat.whispers.set(this.clickedNick, { nick: this.clickedNick, unread: 0, open: false, }); + } this.chat.openConversation(this.clickedNick); } this.hide(); diff --git a/assets/chat/js/menus/ChatUserMenu.js b/assets/chat/js/menus/ChatUserMenu.js index cfc54ceb..14e46161 100644 --- a/assets/chat/js/menus/ChatUserMenu.js +++ b/assets/chat/js/menus/ChatUserMenu.js @@ -24,8 +24,12 @@ const UserMenuSections = [ function userComparator(a, b) { const u1Nick = a.getAttribute('data-username').toLowerCase(); const u2Nick = b.getAttribute('data-username').toLowerCase(); - if (u1Nick < u2Nick) return -1; - if (u1Nick > u2Nick) return 1; + if (u1Nick < u2Nick) { + return -1; + } + if (u1Nick > u2Nick) { + return 1; + } return 0; } @@ -115,8 +119,11 @@ export default class ChatUserMenu extends ChatMenu { section.users.children.length === 1 ? '' : 's' }${this.buildFeatures(section.data.flairs)}`, ); - if (section.searchcount === 0) $(section.container).hide(); - else $(section.container).show(); + if (section.searchcount === 0) { + $(section.container).hide(); + } else { + $(section.container).show(); + } }); } else { this.header.text(`Users (${this.totalcount})`); @@ -126,8 +133,11 @@ export default class ChatUserMenu extends ChatMenu { section.users.children.length === 1 ? '' : 's' }${this.buildFeatures(section.data.flairs)}`, ); - if (section.users.children.length === 0) $(section.container).hide(); - else $(section.container).show(); + if (section.users.children.length === 0) { + $(section.container).hide(); + } else { + $(section.container).show(); + } }); } this.ui.toggleClass('search-in', searching); @@ -206,7 +216,9 @@ export default class ChatUserMenu extends ChatMenu { break; } - if (index < lowestIndex) lowestIndex = index; + if (index < lowestIndex) { + lowestIndex = index; + } } } return lowestIndex > flairs.length @@ -266,12 +278,18 @@ export default class ChatUserMenu extends ChatMenu { let max = items.length; let index = Math.floor((min + max) / 2); while (max > min) { - if (userComparator.apply(this, [usr[0], items[index]]) < 0) max = index; - else min = index + 1; + if (userComparator.apply(this, [usr[0], items[index]]) < 0) { + max = index; + } else { + min = index + 1; + } index = Math.floor((min + max) / 2); } - if (index - 1 < 0) usr.insertBefore(items[0]); - else usr.insertAfter(items[index - 1]); + if (index - 1 < 0) { + usr.insertBefore(items[0]); + } else { + usr.insertAfter(items[index - 1]); + } } else { section.users.append(usr[0]); } diff --git a/assets/chat/js/menus/ChatWhisperUsers.js b/assets/chat/js/menus/ChatWhisperUsers.js index 981e9092..9c72cab9 100644 --- a/assets/chat/js/menus/ChatWhisperUsers.js +++ b/assets/chat/js/menus/ChatWhisperUsers.js @@ -53,8 +53,12 @@ export default class ChatWhisperUsers extends ChatMenu { } else { [...this.chat.whispers.entries()] .sort((a, b) => { - if (a[1].unread === 0) return 1; - if (b[1].unread === 0) return -1; + if (a[1].unread === 0) { + return 1; + } + if (b[1].unread === 0) { + return -1; + } return 0; }) .forEach((e) => this.addConversation(e[0], e[1].unread)); diff --git a/assets/chat/js/messages/ChatBroadcastMessage.js b/assets/chat/js/messages/ChatBroadcastMessage.js index a1c1ced8..ec4657dd 100644 --- a/assets/chat/js/messages/ChatBroadcastMessage.js +++ b/assets/chat/js/messages/ChatBroadcastMessage.js @@ -21,7 +21,9 @@ export default class ChatBroadcastMessage extends ChatEventMessage { .querySelector('#user-template') ?.content.cloneNode(true).firstElementChild; user.title = this.title; - if (colorFlair) user.classList.add(colorFlair.name); + if (colorFlair) { + user.classList.add(colorFlair.name); + } user.innerText = this.user.displayName; const ctrl = document.createElement('span'); @@ -52,7 +54,9 @@ export default class ChatBroadcastMessage extends ChatEventMessage { const attributes = eventTemplate .getAttributeNames() .reduce((object, attributeName) => { - if (attributeName === 'class') return object; + if (attributeName === 'class') { + return object; + } return { ...object, [attributeName]: eventTemplate.getAttribute(attributeName), diff --git a/assets/chat/js/messages/ChatDonationMessage.js b/assets/chat/js/messages/ChatDonationMessage.js index 45148b0e..85a7f40b 100644 --- a/assets/chat/js/messages/ChatDonationMessage.js +++ b/assets/chat/js/messages/ChatDonationMessage.js @@ -34,7 +34,9 @@ export default class ChatDonationMessage extends ChatEventMessage { const colorFlair = usernameColorFlair(chat.flairs, this.user); user.title = this.title; - if (colorFlair) user.classList.add(colorFlair.name); + if (colorFlair) { + user.classList.add(colorFlair.name); + } user.innerText = this.user.displayName; eventTemplate.querySelector('.event-info').append( @@ -55,7 +57,9 @@ export default class ChatDonationMessage extends ChatEventMessage { const attributes = eventTemplate .getAttributeNames() .reduce((object, attributeName) => { - if (attributeName === 'class') return object; + if (attributeName === 'class') { + return object; + } return { ...object, [attributeName]: eventTemplate.getAttribute(attributeName), diff --git a/assets/chat/js/messages/ChatEmoteMessage.js b/assets/chat/js/messages/ChatEmoteMessage.js index 37c61a9a..d5d800b5 100644 --- a/assets/chat/js/messages/ChatEmoteMessage.js +++ b/assets/chat/js/messages/ChatEmoteMessage.js @@ -5,14 +5,22 @@ import MessageTypes from './MessageTypes'; import { EmoteFormatter } from '../formatters'; function ChatEmoteMessageCount(message) { - if (!message || !message.combo) return; + if (!message || !message.combo) { + return; + } let stepClass = 'x2'; - if (message.emotecount >= 50) stepClass = 'x50'; - else if (message.emotecount >= 30) stepClass = 'x30'; - else if (message.emotecount >= 20) stepClass = 'x20'; - else if (message.emotecount >= 10) stepClass = 'x10'; - else if (message.emotecount >= 5) stepClass = 'x5'; + if (message.emotecount >= 50) { + stepClass = 'x50'; + } else if (message.emotecount >= 30) { + stepClass = 'x30'; + } else if (message.emotecount >= 20) { + stepClass = 'x20'; + } else if (message.emotecount >= 10) { + stepClass = 'x10'; + } else if (message.emotecount >= 5) { + stepClass = 'x5'; + } message.ui.setAttribute('data-combo', message.emotecount); message.ui.setAttribute('data-combo-group', stepClass); diff --git a/assets/chat/js/messages/ChatEventMessage.js b/assets/chat/js/messages/ChatEventMessage.js index 7e666a9c..27058189 100644 --- a/assets/chat/js/messages/ChatEventMessage.js +++ b/assets/chat/js/messages/ChatEventMessage.js @@ -17,11 +17,15 @@ export default class ChatEventMessage extends ChatMessage { .querySelector('#event-template') ?.content.cloneNode(true).firstElementChild; - if (this.user && this.user.username && !this.user.isSystem()) + if (this.user && this.user.username && !this.user.isSystem()) { eventTemplate.dataset.username = this.user.username; - if (this.mentioned && this.mentioned.length > 0) + } + if (this.mentioned && this.mentioned.length > 0) { eventTemplate.dataset.mentioned = this.mentioned.join(' ').toLowerCase(); - if (this.slashme) eventTemplate.classList.add('msg-me'); + } + if (this.slashme) { + eventTemplate.classList.add('msg-me'); + } if (this.message) { eventTemplate.querySelector('.event-bottom').innerHTML = diff --git a/assets/chat/js/messages/ChatMessage.js b/assets/chat/js/messages/ChatMessage.js index 0e63a18c..3bf3dca2 100644 --- a/assets/chat/js/messages/ChatMessage.js +++ b/assets/chat/js/messages/ChatMessage.js @@ -50,7 +50,9 @@ export default class ChatMessage extends ChatUIMessage { html(chat = null) { const classes = []; const attr = {}; - if (this.continued) classes.push('msg-continue'); + if (this.continued) { + classes.push('msg-continue'); + } return this.wrap( `${this.buildTime()} ${this.buildMessageTxt(chat)}`, classes, @@ -64,10 +66,11 @@ export default class ChatMessage extends ChatUIMessage { this.message.substring(0, 4).toLowerCase() === '/me ' ? this.message.substring(4) : this.message; - if (!this.unformatted) + if (!this.unformatted) { formatters.forEach((f) => { msg = f.format(chat, msg, this); }); + } return `${msg}`; } @@ -165,7 +168,9 @@ export default class ChatMessage extends ChatUIMessage { setContinued(isContinued) { this.ui.classList.toggle('msg-continue', isContinued); const ctrl = this.ui.querySelector('.ctrl'); - if (ctrl) ctrl.textContent = isContinued ? '' : ': '; + if (ctrl) { + ctrl.textContent = isContinued ? '' : ': '; + } this.continued = isContinued; } diff --git a/assets/chat/js/messages/ChatUserMessage.js b/assets/chat/js/messages/ChatUserMessage.js index f391b3be..610f1219 100644 --- a/assets/chat/js/messages/ChatUserMessage.js +++ b/assets/chat/js/messages/ChatUserMessage.js @@ -34,7 +34,9 @@ export default class ChatUserMessage extends ChatMessage { const classes = []; const attr = {}; - if (this.id) attr['data-id'] = this.id; + if (this.id) { + attr['data-id'] = this.id; + } if (this.user && this.user.username) { classes.push(...this.user.features); attr['data-username'] = this.user.username; @@ -46,20 +48,38 @@ export default class ChatUserMessage extends ChatMessage { } } } - if (this.mentioned && this.mentioned.length > 0) + if (this.mentioned && this.mentioned.length > 0) { attr['data-mentioned'] = this.mentioned.join(' ').toLowerCase(); + } - if (this.isown) classes.push('msg-own'); - if (this.slashme) classes.push('msg-me'); - if (this.historical) classes.push('msg-historical'); - if (this.highlighted) classes.push('msg-highlight'); - if (this.continued && !this.target) classes.push('msg-continue'); - if (this.tag) classes.push(`msg-tagged msg-tagged-${this.tag}`); - if (this.target) classes.push(`msg-whisper`); + if (this.isown) { + classes.push('msg-own'); + } + if (this.slashme) { + classes.push('msg-me'); + } + if (this.historical) { + classes.push('msg-historical'); + } + if (this.highlighted) { + classes.push('msg-highlight'); + } + if (this.continued && !this.target) { + classes.push('msg-continue'); + } + if (this.tag) { + classes.push(`msg-tagged msg-tagged-${this.tag}`); + } + if (this.target) { + classes.push(`msg-whisper`); + } let ctrl = ': '; - if (this.target) ctrl = ' whispered: '; - else if (this.slashme || this.continued) ctrl = ''; + if (this.target) { + ctrl = ' whispered: '; + } else if (this.slashme || this.continued) { + ctrl = ''; + } const colorFlair = usernameColorFlair(chat.flairs, this.user); const user = `${this.buildFeatures(this.user, chat)}