From a018771838367998a71ee239fdf256c1ee1df5dd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 10 Jul 2022 20:42:13 +0300 Subject: Cleanup some lint warnings --- src/main/assets/scripts.js | 50 ++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'src/main') diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index 00d7d616..97525940 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -281,10 +281,10 @@ function showCommentForm(mid, rid) { let submitButton = /** @type {HTMLInputElement} */ (form.querySelector('input[type="submit"]')); let attachButton = form.querySelector('.msg-comment .attach-photo'); - attachButton.addEventListener('click', e => attachCommentPhoto(/** @type {HTMLDivElement} */ (e.target))); + attachButton.addEventListener('click', e => attachCommentPhoto(/** @type {HTMLDivElement} */(e.target))); let textarea = /** @type {HTMLTextAreaElement} */ (form.querySelector('.msg-comment textarea')); - textarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */ (e.target), e)); + textarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */(e.target), e)); autosize(textarea); let validateMessage = () => { @@ -568,12 +568,12 @@ ready(() => { /** @type {HTMLTextAreaElement[]} */ (Array.from(document.querySelectorAll('textarea.replypm'))).forEach(function(e) { e.addEventListener('click', insertPMButtons); e.addEventListener('keypress', function(e) { - postformListener(/** @type {HTMLElement} */ (e.target), e); + postformListener(/** @type {HTMLElement} */(e.target), e); }); }); /** @type {HTMLTextAreaElement[]} */ (Array.from(document.querySelectorAll('#postmsg textarea'))).forEach(function(e) { e.addEventListener('keypress', function(e) { - postformListener(/** @type {HTMLElement} */ (e.target), e); + postformListener(/** @type {HTMLElement} */(e.target), e); }); }); @@ -595,7 +595,7 @@ ready(() => { let replyTextarea = /** @type {HTMLTextAreaElement} */ (opMessage.querySelector('textarea.reply')); if (replyTextarea) { replyTextarea.addEventListener('focus', e => showCommentForm(pageMID, 0)); - replyTextarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */ (e.target), e)); + replyTextarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */(e.target), e)); if (!window.location.hash) { replyTextarea.focus(); } @@ -736,34 +736,40 @@ ready(() => { } }); Array.from(document.querySelectorAll('[data-uri]')).forEach(el => { - let dataUri = el.getAttribute('data-uri'); + let dataUri = el.getAttribute('data-uri') || ''; if (dataUri) { setTimeout(() => fetchUserUri(dataUri, user => { let header = el.closest('.msg-header'); - Array.from(header.querySelectorAll('.a-username')).forEach(a => { - a.setAttribute('href', dataUri); - let img = a.querySelector('img'); - if (img && user.icon) { - img.setAttribute('src', user.icon.url); - img.setAttribute('alt', user.preferredUsername); - } - let textNode = a.childNodes[0]; - if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { - let uname = document.createTextNode(user.preferredUsername); - a.replaceChild(uname, a.firstChild); - } - }); + if (header) { + Array.from(header.querySelectorAll('.a-username')).forEach(a => { + a.setAttribute('href', dataUri); + let img = a.querySelector('img'); + if (img && user.icon) { + img.setAttribute('src', user.icon.url); + img.setAttribute('alt', user.preferredUsername); + } + let textNode = a.childNodes[0]; + if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue && textNode.nodeValue.trim().length > 0) { + let uname = document.createTextNode(user.preferredUsername); + if (a.firstChild) { + a.replaceChild(uname, a.firstChild); + } + } + }); + } }), 100); } }); Array.from(document.querySelectorAll('[data-user-uri]')).forEach(el => { - let dataUri = el.getAttribute('href'); + let dataUri = el.getAttribute('href') || ''; if (dataUri) { setTimeout(() => fetchUserUri(dataUri, user => { let textNode = el.childNodes[0]; - if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { + if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue && textNode.nodeValue.trim().length > 0) { let uname = document.createTextNode(`@${user.preferredUsername}`); - el.replaceChild(uname, el.firstChild); + if (el.firstChild) { + el.replaceChild(uname, el.firstChild); + } } }), 100); } -- cgit v1.2.3