aboutsummaryrefslogtreecommitdiff
path: root/src/main/assets
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-07-10 20:42:13 +0300
committerGravatar Vitaly Takmazov2022-07-10 20:42:13 +0300
commita018771838367998a71ee239fdf256c1ee1df5dd (patch)
tree85735938c6b90dea2e2a49b56b813591f7e0d7a2 /src/main/assets
parenta999bbb93bc6d2e15f7edfcccc590b83eee3c8ca (diff)
Cleanup some lint warnings
Diffstat (limited to 'src/main/assets')
-rw-r--r--src/main/assets/scripts.js50
1 files changed, 28 insertions, 22 deletions
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);
}