Fedi.CrowdedGames.Group/JS/mail.js
2025-04-28 19:23:37 -07:00

64 lines
2.6 KiB
JavaScript

import * as MastodonAPI from "./MastodonAPI.js";
import * as BlueskyAPI from "./BlueskyAPI.js";
import * as TumblrAPI from "./TumblrAPI.js";
// MAKE SURE THESE ARE SYNCED!
// Mastodon
let MastodonWebsite = "https://wetdry.world";
let MastodonClientID = "mastodon_client_id";
let MastodonClientSecret = "mastodon_client_secret";
let MastodonAccessToken = "mastodon_access_token";
let MastodonTokenType = "mastodon_token_type";
// Bluesky
let BlueskyApp = "https://bsky.app";
let BlueskyPDS = "https://bsky.social";
let BlueskyPKCEverifer = "bluesky_pkce_verifier";
let BlueskyPKCEchallenge = "bluesky_pkce_challenge";
let BlueskyPublicKey = "bluesky_public_key";
let BlueskyNonce = "bluesky_nonce";
// Below is the thing it populates if you login.
async function PopulateFavorites() {
let Favorites = await MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
let FavoritesArea = document.getElementsByClassName("Favorites")[0];
// Populate the favorites area.
for (let i in Favorites) {
FavoritesArea.innerHTML += "<article style='top:" + getRandomArbitrary(0, 84) + "%; left: " + getRandomArbitrary(0, 84) + "%;' class='Favorite'></article>";
FavoritesArea.getElementsByClassName("Favorite")[i].innerHTML = Favorites[i].content;
}
}
async function PopulateBookmarks() {
let Bookmarks = await MastodonAPI.GetBookmarks(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
let BookmarksArea = document.getElementsByClassName("Bookmarks")[0];
// Populate the Bookmarks area.
for (let i in Bookmarks) {
BookmarksArea.innerHTML += "<article style='top:" + getRandomArbitrary(0, 84) + "%; left: " + getRandomArbitrary(0, 84) + "%;' class='Bookmark'></article>";
BookmarksArea.getElementsByClassName("Bookmark")[i].innerHTML = Bookmarks[i].content;
}
}
async function PopulateNotifications() {
let Notifications = await MastodonAPI.GetNotifications(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
let NotificationsArea = document.getElementsByClassName("Notifications")[0];
// Populate the Conversations area.
for (let i in Notifications) {
NotificationsArea.innerHTML += "<article style='top:" + getRandomArbitrary(0, 84) + "%; left: " + getRandomArbitrary(0, 84) + "%;' class='Notification'></article>";
NotificationsArea.getElementsByClassName("Notification")[i].innerHTML = Notifications[i].status.content;
}
}
// Populate the areas.
PopulateFavorites();
PopulateBookmarks();
PopulateNotifications();
// Functions stolen elsewhere
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}