aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/assets/scripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/assets/scripts.js')
-rw-r--r--juick-server/src/main/assets/scripts.js123
1 files changed, 78 insertions, 45 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js
index 8060bd71..6cc51d82 100644
--- a/juick-server/src/main/assets/scripts.js
+++ b/juick-server/src/main/assets/scripts.js
@@ -179,7 +179,7 @@ function initWS() {
window.addEventListener('beforeunload', () => {
clearInterval(keepAlive);
ws.close();
- })
+ });
}
function wsSendKeepAlive() {
@@ -359,20 +359,20 @@ function showCommentForm(mid, rid) {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location.href = new URL(`${mid}#${result.newMessage.rid}`, window.location.href);
- } else {
- alert(result.text);
- }
- window.location.reload(true);
- });
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.newMessage) {
+ window.location.href = new URL(`${mid}#${result.newMessage.rid}`, window.location.href);
+ } else {
+ alert(result.text);
+ }
+ window.location.reload(true);
+ });
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
}
@@ -642,6 +642,21 @@ function addTag(tag) {
return false;
}
+function fetchUserUri(dataUri, callback) {
+ let data = new FormData();
+ data.append('uri', dataUri);
+ fetch('/u/', {
+ method: 'POST',
+ body: data
+ }).then(handleErrors)
+ .then(response => {
+ return response.json();
+ })
+ .then(json => {
+ callback(json);
+ });
+}
+
/******************************************************************************/
function ready(fn) {
@@ -720,21 +735,21 @@ ready(function () {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href);
- } else {
- alert(result.text);
- }
- });
- } else {
- alert('Something went wrong :(');
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.newMessage) {
+ window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href);
+ } else {
+ alert(result.text);
+ }
+ });
+ } else {
+ alert('Something went wrong :(');
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
}
@@ -746,21 +761,21 @@ ready(function () {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.to) {
- window.location = new URL('/pm/sent', window.location.href);
- } else {
- alert('Something went wrong :(');
- }
- });
- } else {
- alert('Something went wrong :(');
- }
- }).catch(error => {
- alert(error.message);
- });
+ .then(response => {
+ if (response.ok) {
+ response.json().then(result => {
+ if (result.to) {
+ window.location = new URL('/pm/sent', window.location.href);
+ } else {
+ alert('Something went wrong :(');
+ }
+ });
+ } else {
+ alert('Something went wrong :(');
+ }
+ }).catch(error => {
+ alert(error.message);
+ });
e.preventDefault();
});
});
@@ -848,6 +863,24 @@ ready(function () {
article.classList.add('nsfw');
}
});
+ document.querySelectorAll('[data-uri]').forEach(el => {
+ fetchUserUri(el.getAttribute('data-uri'), user => {
+ let header = el.closest('.msg-header');
+ header.querySelectorAll('.a-username').forEach(a => {
+ a.setAttribute('href', user.uri);
+ let img = a.querySelector('img');
+ if (img && user.avatar) {
+ img.setAttribute('src', user.avatar);
+ img.setAttribute('alt', user.uname);
+ }
+ let textNode = a.childNodes[0];
+ if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) {
+ let uname = document.createTextNode(user.uname);
+ a.replaceChild(uname, a.firstChild);
+ }
+ });
+ });
+ });
initWS();
window.addEventListener('pagehide', wsShutdown);