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"; document.getElementById("body").style.display = "none";
} }
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
function showFullscreenImage(element) { function showFullscreenImage(element) {
imageSrc = element.getAttribute('src'); imageSrc = element.getAttribute('src');
@ -40,6 +43,29 @@ function ready() {
document.addEventListener("DOMContentLoaded", 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 // Загрузка HTML из файла при загрузке URL
async function bodyFetch(url) { async function bodyFetch(url) {
@ -55,6 +81,7 @@ async function bodyFetch(url) {
if (response.ok) { // если HTTP-статус в диапазоне 200-299 if (response.ok) { // если HTTP-статус в диапазоне 200-299
// получаем тело ответа (см. про этот метод ниже) // получаем тело ответа (см. про этот метод ниже)
let text = await response.text(); let text = await response.text();
if (tplUrl == 'news.tpl.html') {fetchData();}
body.innerHTML = text; body.innerHTML = text;
} else { } else {
body.innerHTML = "Ой всё сломалось :("; body.innerHTML = "Ой всё сломалось :(";
@ -63,32 +90,32 @@ async function bodyFetch(url) {
let query = window.location.pathname; let query = window.location.pathname;
switch (query) { switch (query) {
case "/news": case "/news":
bodyFetch(query); bodyFetch(query);
break; break;
case "/overview": case "/overview":
bodyFetch(query); bodyFetch(query);
break; break;
case "/download": case "/download":
bodyFetch(query); bodyFetch(query);
break; break;
case "/donate": case "/donate":
bodyFetch(query); bodyFetch(query);
break; break;
case "/cooperation": case "/cooperation":
bodyFetch(query); bodyFetch(query);
break; break;
case "/about": case "/about":
bodyFetch(query); bodyFetch(query);
break; break;
default: default:
bodyFetch(); bodyFetch();
} }
@ -115,6 +142,7 @@ let fetchPage = async function(evt) {
try { try {
const response = await fetch(tplUrl, { signal }); const response = await fetch(tplUrl, { signal });
text = await response.text(); text = await response.text();
if (tplUrl == 'news.tpl.html') {fetchData();}
} catch (error) { } catch (error) {
// DOMException: The user aborted a request. // DOMException: The user aborted a request.
console.log('Error: ', error) 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> </ul>
</article> </article>
<script src="assets/js/toot.js"></script>
<!-- <!--
<nav class="blog-pagination" aria-label="Pagination"> <nav class="blog-pagination" aria-label="Pagination">
<a class="btn btn-outline-primary rounded-pill" href="#">Older</a> <a class="btn btn-outline-primary rounded-pill" href="#">Older</a>