mail call!

This commit is contained in:
CatAClock 2025-04-22 15:49:11 -07:00
parent 6885fe7f0e
commit 811e47e08c
4 changed files with 161 additions and 9 deletions

44
CSS/mail.css Normal file
View file

@ -0,0 +1,44 @@
.Favorite {
border-style: solid;
border-width: 2px;
background-color: #ffff8f;
position: absolute;
width: 15%;
height: 15%;
overflow: hidden;
}
.Favorite:hover {
overflow: visible;
}
.Bookmark {
border-style: solid;
border-width: 2px;
background-color: #ff998f;
position: absolute;
width: 15%;
height: 15%;
overflow: hidden;
}
.Bookmark:hover {
overflow: visible;
}
.Notification {
border-style: solid;
border-width: 2px;
background-color: #8fffaf;
position: absolute;
width: 15%;
height: 15%;
overflow: hidden;
}
.Notification:hover {
overflow: visible;
}

View file

@ -4,15 +4,19 @@
<meta name="description" content="Change the fucking channel already!">
<title>The Fediverse</title>
<link rel="stylesheet" href="../CSS/mail.css">
<script type="module" src="../JS/mail.js"></script>
</head>
<body style="margin: 0px; text-align: center;">
<header>
<body style="margin: 0px; text-align: center;">
<section style="position: absolute; width: 100%; height: 100%" class="Favorites"></section>
<section style="position: absolute; width: 100%; height: 100%" class="Bookmarks"></section>
<section style="position: absolute; width: 100%; height: 100%" class="Notifications"></section>
<header style="position: relative; z-index: 1;">
<h1>Mail</h1>
<p class="Login"><em>Login</em></p>
<p class="Logout" style="visibility: hidden;"><em>Logout</em></p>
<p onclick="history.back()"><b>Back</b></p>
</header>
<p>Just go back. It ain't ready yet...</p>
<p class="Login">Login</p>
<p onclick="history.back()"><b>OK</b></p>
</body>
</html>

View file

@ -3,7 +3,7 @@ export const Scopes = "read write follow push";
export async function GetPublicTimeline(Local = false, Remote = false) {
let Timeline;
if (Local == true && Remote == true) {
console.log("Don't set both Local and Remote timelines to true.");
console.error("Don't set both Local and Remote timelines to true.");
}
if (Local == true) {

View file

@ -1,16 +1,120 @@
import * as ActivityPub from "./ActivityPub.js";
let LoginButton = document.getElementsByClassName("Login")[0];
let LogoutButton = document.getElementsByClassName("Logout")[0];
let Origin = window.location.origin + "/HTML/mail"
LoginButton.onclick = (event) => {
HandleLogin();
HandleAuthentication();
}
async function HandleLogin() {
let Origin = window.location.origin + "/HTML/mail";
LogoutButton.onclick = (event) => {
console.log("Does nothing so far.");
}
async function HandleAuthentication() {
let InstanceData = await fetch("https://wetdry.world/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + Origin + "&scopes=" + ActivityPub.Scopes, {method: "POST"})
.then((response) => response.json());
// Save the client stuff as cookies (STRICTLY THIS SITE!).
document.cookie = "client_id=" + InstanceData.client_id + ";samesite=strict;path=/;expires=Thu, 01 Jan 9999 00:00:00 GMT;";
document.cookie = "client_secret=" + InstanceData.client_secret + ";samesite=strict;path=/;expires=Thu, 01 Jan 9999 00:00:00 GMT;";
// Now authenticate the app.
let InstanceInfo = await fetch("https://wetdry.world/api/v1/instance", {method: "GET"})
.then((response) => response.json());
document.location.href = "https://wetdry.world/oauth/authorize?client_id=" + InstanceData.client_id + "&redirect_uri=" + Origin + "&response_type=code&scope=" + ActivityPub.Scopes;
}
// When the website starts, check to see if you actually went and got a code.
async function HandleLogin() {
if (document.location.href.split("code=").length > 1 && document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=") > 1) {
let code = document.location.href.split("code=")[1];
let ClientID = document.cookie.split("; ").find((row) => row.startsWith("client_id="))?.split("=")[1];
let ClientSecret = document.cookie.split("; ").find((row) => row.startsWith("client_secret="))?.split("=")[1];
let AuthenticationToken = await fetch("https://wetdry.world/oauth/token?client_id=" + ClientID + "&client_secret=" + ClientSecret + "&redirect_uri=" + Origin + "&grant_type=authorization_code&code=" + code, {method: "POST"})
.then((response) => response.json());
// Cookify These
document.cookie = "access_token=" + AuthenticationToken.access_token + ";samesite=strict;path=/;expires=Thu, 01 Jan 9999 00:00:00 GMT;";
document.cookie = "token_type=" + AuthenticationToken.token_type + ";samesite=strict;path=/;expires=Thu, 01 Jan 9999 00:00:00 GMT;";
}
}
function CheckLogin() {
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=").length > 1) {
// Swap the buttons
LoginButton.remove();
LogoutButton.setAttribute("style", "");
}
}
// Below is the thing it populates if you login.
async function PopulateFavorites() {
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith("token_type="))?.split("=")[1];
let Favorites = await fetch("https://wetdry.world/api/v1/favourites", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
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() {
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith("token_type="))?.split("=")[1];
let Bookmarks = await fetch("https://wetdry.world/api/v1/bookmarks", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
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() {
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith("token_type="))?.split("=")[1];
let Notifications = await fetch("https://wetdry.world/api/v1/notifications", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
console.log(Notifications);
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;
}
}
}
// Runs on website start.
// Remove traces of "login".
CheckLogin();
// Authentication.
HandleLogin();
// 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;
}