This commit is contained in:
Valeria Fadeeva 2023-12-15 22:40:07 +05:00
parent 33d5d598a1
commit efbb43cfad
1 changed files with 87 additions and 81 deletions

View File

@ -1,35 +1,3 @@
let query = window.location.pathname;
if (query == "/news" || query == "/mastodon") {
let tplUrl = 'json/mastodon-tpl.html';
let response = await fetch(tplUrl);
var tpl = "";
let log = document.getElementById('log');
log.innerHTML = "";
const controller = new AbortController();
const signal = controller.signal;
// Cancel the fetch request in 500ms
setTimeout(() => controller.abort(), 500);
try {
const response = await fetch(tplUrl, {signal});
tpl = await response.text();
} catch(error) {
// DOMException: The user aborted a request.
console.log('Error: ', error);
log.innerHTML = "<p>1) Ой всё сломалось :(</p>";
}
if(!tpl) {
log.innerHTML = "<p>2) Ой всё сломалось :(</p>";
}
// else {
// log.innerHTML = tpl;
// }
async function fetchData() {
var log = document.getElementById('log');
@ -106,5 +74,43 @@ if (query == "/news" || query == "/mastodon") {
window.open(url, '_blank').focus();
}
async function getMastodonPage() {
let tplUrl = 'json/mastodon-tpl.html';
let response = await fetch(tplUrl);
var tpl = "";
let log = document.getElementById('log');
if (!log) {
setTimeout(getMastodonPage, 1000);
}
log.innerHTML = "";
const controller = new AbortController();
const signal = controller.signal;
// Cancel the fetch request in 500ms
setTimeout(() => controller.abort(), 500);
try {
const response = await fetch(tplUrl, {signal});
tpl = await response.text();
} catch(error) {
// DOMException: The user aborted a request.
console.log('Error: ', error);
log.innerHTML = "<p>1) Ой всё сломалось :(</p>";
}
if(!tpl) {
log.innerHTML = "<p>2) Ой всё сломалось :(</p>";
}
fetchData();
}
let query = window.location.pathname;
if (query == "/news" || query == "/mastodon") {
getMastodonPage();
}