This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/account/inbox.js
2024-05-27 22:02:41 +00:00

47 lines
1.4 KiB
JavaScript

ExpandMessages();
function ExpandMessages() {
const Messages = document.getElementById('messages');
for (let message of Messages.children) {
let Expanded = false;
let ContentDiv = null;
const ViewButton = message.querySelector('a.btn[href^="/inbox/messages"]');
const MessageID = ViewButton.getAttribute('href').split('/')[3];
const ExpandButton = document.createElement('button');
ExpandButton.classList = 'btn btn-outline-warning px-4 mt-1';
ExpandButton.innerText = 'Expand';
ViewButton.parentElement.appendChild(ExpandButton);
ExpandButton.addEventListener('click', function () {
if (ContentDiv === null) {
fetch('https://polytoria.com/inbox/messages/' + MessageID)
.then((response) => {
if (!response.ok) {
throw new Error('Network not ok');
}
return response.text();
})
.then((data) => {
const Doc = new DOMParser().parseFromString(data, 'text/html');
const MessageContent = Doc.querySelector('p.mb-0').innerText;
ContentDiv = document.createElement('div');
ContentDiv.classList = 'py-2';
ContentDiv.innerText = MessageContent;
message.appendChild(ContentDiv);
})
.catch((error) => {
console.log(error);
});
}
Expanded = !Expanded;
ExpandButton.innerText = Expanded === false ? 'Expand' : 'Minimize';
ContentDiv.style.display = Expanded === false ? 'none' : 'block';
});
}
}