From 7bbbcf0df392be397ce70e78d218e0d2fcd0815a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 7 Jun 2023 21:15:50 +0300 Subject: scripts: cleanup remaining lint warnings --- src/main/assets/icon.js | 1 - src/main/assets/scripts.js | 42 ++++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/main/assets/icon.js b/src/main/assets/icon.js index c94a1663..5cd787a5 100644 --- a/src/main/assets/icon.js +++ b/src/main/assets/icon.js @@ -26,7 +26,6 @@ function wrapSpinner(html, klass) { * */ export default function renderIcons() { - var render = true var icons = document.querySelectorAll('[data-icon]') for (var i = 0; i < icons.length; i++) { diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index 4cb06966..94f79424 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -500,7 +500,7 @@ function toggleWL(e, name) { .catch(console.err) return false } - +/* function getTags() { fetch('/api/tags?hash=' + document.getElementById('body').getAttribute('data-hash'), { credentials: 'omit' @@ -513,28 +513,30 @@ function getTags() { }).catch(console.error) return false } - +*/ function addTag(tag) { document.forms['postmsg'].body.value = '*' + tag + ' ' + document.forms['postmsg'].body.value return false } -function fetchUserUri(dataUri, callback) { +function fetchUserUri(dataUri) { let data = new FormData() data.append('uri', dataUri) - fetch('/api/u/', { - method: 'POST', - body: data - }).then(handleErrors) - .then(response => { - return response.json() - }) - .then(json => { - callback(json) - }) - .catch(e => { - callback({ uname: dataUri, uri: dataUri }) - }) + return new Promise((resolve) => { + fetch('/api/u/', { + method: 'POST', + body: data + }).then(handleErrors) + .then(response => { + return response.json() + }) + .then(json => { + resolve(json) + }) + .catch(() => { + resolve({ uname: dataUri, uri: dataUri }) + }) + }) } const registerServiceWorker = () => { @@ -640,7 +642,7 @@ ready(() => { if (opMessage) { let replyTextarea = /** @type {HTMLTextAreaElement} */ (opMessage.querySelector('textarea.reply')) if (replyTextarea) { - replyTextarea.addEventListener('focus', e => showCommentForm(pageMID, 0)) + replyTextarea.addEventListener('focus', () => showCommentForm(pageMID, 0)) replyTextarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */(e.target), e)) if (!window.location.hash) { replyTextarea.focus() @@ -777,7 +779,7 @@ ready(() => { Array.from(document.querySelectorAll('[data-uri]')).forEach(el => { let dataUri = el.getAttribute('data-uri') || '' if (dataUri) { - setTimeout(() => fetchUserUri(dataUri, user => { + setTimeout(() => fetchUserUri(dataUri).then(user => { let header = el.closest('.msg-header') Array.from(header.querySelectorAll('.a-username')).forEach(a => { a.setAttribute('href', user.url || user.uri) @@ -798,7 +800,7 @@ ready(() => { Array.from(document.querySelectorAll('[data-user-uri]')).forEach(el => { let dataUri = el.getAttribute('href') || '' if (dataUri) { - setTimeout(() => fetchUserUri(dataUri, user => { + setTimeout(() => fetchUserUri(dataUri).then(user => { let textNode = el.childNodes[0] if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { let uname = document.createTextNode(`@${user.uname}`) @@ -825,7 +827,7 @@ ready(() => { const button = document.getElementById('notifications_toggle') if (button) { button.addEventListener('click', () => { - Notification.requestPermission(function(result) { notificationsCheckPermissions(button) }) + Notification.requestPermission(() => { notificationsCheckPermissions(button) }) }) notificationsCheckPermissions(button) } -- cgit v1.2.3