This commit is contained in:
Valeria Fadeeva 2023-12-10 01:21:40 +05:00
parent 385604b7e5
commit 7f17905bbc
3 changed files with 48 additions and 50 deletions

View File

@ -9,6 +9,9 @@ function hidePage() {
document.getElementById("body").style.display = "none";
}
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
function showFullscreenImage(element) {
imageSrc = element.getAttribute('src');
@ -40,6 +43,29 @@ function ready() {
document.addEventListener("DOMContentLoaded", ready);
const log = document.getElementById('log');
log.innerHTML = "";
async function fetchData() {
var serverAddress = "techhub.social";
const response = await fetch(`https://${serverAddress}/api/v1/accounts/111518136987654656/statuses`);
const data = await response.json();
data.forEach(obj => {
Object.entries(obj).forEach(([key, value]) => {
if (key == "id") {
log.innerHTML = log.innerHTML + `<iframe src="https://techhub.social/@Melawy/${value}/embed" class="mastodon-embed" style="max-width: 100%; border: 0" height="100%" width="60%" allowfullscreen="allowfullscreen"></iframe>` + '<br>';
}
});
log.innerHTML = log.innerHTML + '<br>';
});
}
// Загрузка HTML из файла при загрузке URL
async function bodyFetch(url) {
@ -55,6 +81,7 @@ async function bodyFetch(url) {
if (response.ok) { // если HTTP-статус в диапазоне 200-299
// получаем тело ответа (см. про этот метод ниже)
let text = await response.text();
if (tplUrl == 'news.tpl.html') {fetchData();}
body.innerHTML = text;
} else {
body.innerHTML = "Ой всё сломалось :(";
@ -63,32 +90,32 @@ async function bodyFetch(url) {
let query = window.location.pathname;
switch (query) {
case "/news":
bodyFetch(query);
break;
case "/news":
bodyFetch(query);
break;
case "/overview":
bodyFetch(query);
break;
case "/overview":
bodyFetch(query);
break;
case "/download":
bodyFetch(query);
break;
case "/download":
bodyFetch(query);
break;
case "/donate":
bodyFetch(query);
break;
case "/donate":
bodyFetch(query);
break;
case "/cooperation":
bodyFetch(query);
break;
case "/cooperation":
bodyFetch(query);
break;
case "/about":
bodyFetch(query);
break;
case "/about":
bodyFetch(query);
break;
default:
bodyFetch();
default:
bodyFetch();
}
@ -115,6 +142,7 @@ let fetchPage = async function(evt) {
try {
const response = await fetch(tplUrl, { signal });
text = await response.text();
if (tplUrl == 'news.tpl.html') {fetchData();}
} catch (error) {
// DOMException: The user aborted a request.
console.log('Error: ', error)

View File

@ -1,28 +0,0 @@
const log = document.getElementById('log');
log.innerHTML = "";
async function fetchData() {
var serverAddress = "techhub.social";
const response = await fetch(`https://${serverAddress}/api/v1/accounts/111518136987654656/statuses`);
const data = await response.json();
data.forEach(obj => {
Object.entries(obj).forEach(([key, value]) => {
if (key == "id") {
log.innerHTML = log.innerHTML + `<iframe src="https://techhub.social/@Melawy/${value}/embed" class="mastodon-embed" style="max-width: 100%; border: 0" height="100%" width="60%" allowfullscreen="allowfullscreen"></iframe>` + '<br>';
}
});
log.innerHTML = log.innerHTML + '<br>';
});
}
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
document.addEventListener("DOMContentLoaded", fetchData);

View File

@ -173,8 +173,6 @@
</ul>
</article>
<script src="assets/js/toot.js"></script>
<!--
<nav class="blog-pagination" aria-label="Pagination">
<a class="btn btn-outline-primary rounded-pill" href="#">Older</a>