169 lines
5.7 KiB
JavaScript
169 lines
5.7 KiB
JavaScript
import * as MastodonAPI from "./MastodonAPI.js";
|
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
|
import * as TumblrAPI from "./TumblrAPI.js";
|
|
import * as Variables from "./Variables.js";
|
|
|
|
// GLOBAL VARS
|
|
// fuck you. I see why website developers use divs so fucking often.
|
|
let Warning = document.getElementsByClassName("WarningMessage")[0];
|
|
let Main = document.getElementsByClassName("MainBefore")[0];
|
|
let ContainerContainer = document.getElementsByClassName("PostContainerContainer")[0];
|
|
|
|
let BrowserWidth = window.innerWidth;
|
|
let BrowserHeight = window.innerHeight;
|
|
|
|
let ArrowsButton = document.getElementsByClassName("Arrow");
|
|
let SettingButton = document.getElementsByClassName("Setting")[0];
|
|
let MailButton = document.getElementsByClassName("Mail")[0];
|
|
let PostingButton = document.getElementsByClassName("Posting")[0];
|
|
|
|
// Sounds
|
|
const ButtonSound = new Audio("Audio/button-305770.mp3");
|
|
const WarningClick = new Audio("Audio/button-pressed-38129.mp3");
|
|
const BackgroundMusic = new Audio("Audio/soft-piano-music-312509.mp3");
|
|
|
|
// Update a timer
|
|
function UpdateTime() {
|
|
let TimeNow = new Date();
|
|
let Hour = TimeNow.getHours();
|
|
let Minute = TimeNow.getMinutes();
|
|
|
|
var WebsiteTime = document.getElementsByClassName("Time")[0]
|
|
WebsiteTime.innerHTML = "";
|
|
if (Hour < 10) {
|
|
WebsiteTime.innerHTML = WebsiteTime.innerHTML + "0" + Hour;
|
|
} else {
|
|
WebsiteTime.innerHTML = WebsiteTime.innerHTML + Hour;
|
|
}
|
|
WebsiteTime.innerHTML = WebsiteTime.innerHTML + ":";
|
|
if (Minute < 10) {
|
|
WebsiteTime.innerHTML = WebsiteTime.innerHTML + "0" + Minute;
|
|
} else {
|
|
WebsiteTime.innerHTML = WebsiteTime.innerHTML + Minute;
|
|
}
|
|
}
|
|
|
|
setInterval(UpdateTime, 1000);
|
|
|
|
// When the window is resized
|
|
onresize = (event) => {
|
|
BrowserWidth = window.innerWidth;
|
|
BrowserHeight = window.innerHeight;
|
|
window.dispatchEvent(new Event("load"));
|
|
}
|
|
|
|
// When the window finally reloads
|
|
onload = (event) => {
|
|
Warning.setAttribute("style", "height: " + BrowserHeight + "px; width: " + BrowserWidth + "px;");
|
|
Main.setAttribute("style", "height: " + BrowserHeight + "px; width: " + BrowserWidth + "px;");
|
|
ArrowsButton[1].setAttribute("style", "left: " + (BrowserWidth - 100) + "px;");
|
|
}
|
|
|
|
// On clicking the warning message
|
|
Warning.onclick = (event) => {
|
|
Warning.classList.add("WarningFadeOutAnimation");
|
|
// fixes a damn stupid bug
|
|
document.getElementsByClassName("BlinkAnimation")[0].classList.remove("BlinkAnimation");
|
|
Main.classList.add("MainFadeInAnimation");
|
|
Main.classList.remove("MainBefore");
|
|
WarningClick.play();
|
|
setTimeout(() => {
|
|
Main.classList.remove("MainFadeInAnimation");
|
|
Main.classList.add("MainAfter");
|
|
BackgroundMusic.play();
|
|
}, 5000);
|
|
Main = document.getElementsByClassName("MainFadeInAnimation")[0];
|
|
PosterContainerUpdate();
|
|
}
|
|
|
|
// Clicking the next button
|
|
ArrowsButton[1].onclick = (event) => {
|
|
if (!ContainerContainer.classList.contains("NextAnimation")) {
|
|
ContainerContainer.classList.add("NextAnimation");
|
|
ButtonSound.play();
|
|
console.log("loading next posts...");
|
|
setTimeout(() => {
|
|
ContainerContainer.classList.remove("NextAnimation");
|
|
}, 1000);
|
|
}
|
|
PosterContainerUpdate();
|
|
}
|
|
|
|
// Clicking the back button
|
|
ArrowsButton[0].onclick = (event) => {
|
|
if (!ContainerContainer.classList.contains("BackAnimation")) {
|
|
ContainerContainer.classList.add("BackAnimation");
|
|
ButtonSound.play();
|
|
console.log("getting previous posts...");
|
|
setTimeout(() => {
|
|
ContainerContainer.classList.remove("BackAnimation");
|
|
}, 1000);
|
|
}
|
|
PosterContainerUpdate();
|
|
}
|
|
|
|
// Call this to update the things :)
|
|
async function PosterContainerUpdate() {
|
|
let Lim = 6;
|
|
// Variables for the public timelines. Only for mastodon
|
|
let LocalVar = localStorage.getItem("Local");
|
|
var LocalTrue = (LocalVar === "true");
|
|
let RemoteVar = localStorage.getItem("Remote");
|
|
var RemoteTrue = (RemoteVar === "true");
|
|
let Website = localStorage.getItem(Variables.MastodonWebsite);
|
|
// Mastodon gaining of timeline
|
|
let MastodonTimeline;
|
|
if (localStorage.getItem(Variables.MastodonWebsite) == null) {
|
|
// The default website is Wetdry :3
|
|
MastodonTimeline = await MastodonAPI.GetPublicTimeline(LocalTrue, RemoteTrue, "https://wetdry.world");
|
|
} else {
|
|
MastodonTimeline = await MastodonAPI.GetTimeline();
|
|
}
|
|
// Bluesky gaining of timeline
|
|
let BlueskyTimeline;
|
|
if (localStorage.getItem(Variables.BlueskyPDS) == null) {
|
|
console.log("No Bluesky instance. multiplying mastodon posts by 2...");
|
|
Lim = Lim * 2;
|
|
} else {
|
|
BlueskyTimeline = await BlueskyAPI.GetTimeline();
|
|
}
|
|
// Counters. The first counter counts the posts in the gained timelines...
|
|
// The second increments to another timeline once posts hit the "limit".
|
|
let counter = 0;
|
|
let countergroup = 0;
|
|
let CenterContainer = document.getElementsByClassName("PostContainer")[2].children;
|
|
for (let i in CenterContainer) {
|
|
switch(countergroup) {
|
|
// Bsky
|
|
case 0:
|
|
CenterContainer[i].getElementsByClassName("PostContent")[0].innerHTML = BlueskyTimeline.feed[counter].post.record.text;
|
|
CenterContainer[i].getElementsByClassName("Username")[0].innerHTML = BlueskyTimeline.feed[counter].post.author.handle;
|
|
break;
|
|
// Mastodon
|
|
case 1:
|
|
CenterContainer[i].getElementsByClassName("PostContent")[0].innerHTML = MastodonTimeline[counter].content;
|
|
CenterContainer[i].getElementsByClassName("Username")[0].innerHTML = MastodonTimeline[counter].account.username;
|
|
break;
|
|
}
|
|
counter = counter + 1;
|
|
if (counter >= Lim) {
|
|
counter = 0;
|
|
countergroup = countergroup + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Open the settings
|
|
SettingButton.onclick = (event) => {
|
|
window.location.href = "./HTML/setting.html";
|
|
}
|
|
|
|
// Open the notifs, private message, favorites, ... anything mail related!
|
|
MailButton.onclick = (event) => {
|
|
window.location.href = "./HTML/mail.html";
|
|
}
|
|
|
|
// Open the posting area
|
|
PostingButton.onclick = (event) => {
|
|
window.location.href = "./HTML/post.html";
|
|
}
|