Made it more explicit that I am not using ActivityPub

This commit is contained in:
CatAClock 2025-04-23 16:02:44 -07:00
parent 32065edbd5
commit 2a20fd544e
7 changed files with 145 additions and 98 deletions

View file

@ -1,20 +0,0 @@
export const Scopes = "read write follow push";
export async function GetPublicTimeline(Local = false, Remote = false) {
let Timeline;
if (Local == true && Remote == true) {
console.error("Don't set both Local and Remote timelines to true.");
}
if (Local == true) {
Timeline = await fetch("https://wetdry.world/api/v1/timelines/public?limit=12&local=true")
.then((response) => response.json());
} else if (Remote == true) {
Timeline = await fetch("https://wetdry.world/api/v1/timelines/public?limit=12&remote=true")
.then((response) => response.json());
} else {
Timeline = await fetch("https://wetdry.world/api/v1/timelines/public?limit=12")
.then((response) => response.json());
}
return Timeline;
}

0
JS/BlueskyAPI.js Normal file
View file

101
JS/MastodonAPI.js Normal file
View file

@ -0,0 +1,101 @@
export const Scopes = "read write follow push";
// Gets the public timeline.
export async function GetPublicTimeline(Local = false, Remote = false, Website) {
let Timeline;
if (Local == true && Remote == true) {
console.error("Don't set both Local and Remote timelines to true.");
return Timeline;
}
if (Local == true) {
Timeline = await fetch(Website + "/api/v1/timelines/public?limit=12&local=true")
.then((response) => response.json());
} else if (Remote == true) {
Timeline = await fetch(Website + "/api/v1/timelines/public?limit=12&remote=true")
.then((response) => response.json());
} else {
Timeline = await fetch(Website + "/api/v1/timelines/public?limit=12")
.then((response) => response.json());
}
return Timeline;
}
// Gets the favorites of a user that you have access to.
export async function GetFavorites(Website, MastodonAccessToken, MastodonTokenType) {
let Favorites;
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
}
return Favorites;
}
// Gets the bookmarks of a user that you have access to.
export async function GetBookmarks(Website, MastodonAccessToken, MastodonTokenType) {
let Bookmarks;
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
}
return Bookmarks;
}
// Gets the notifications of a user that you have access to.
export async function GetNotifications(Website, MastodonAccessToken, MastodonTokenType) {
let Notifications;
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
// Get the varaibles that are stored in cookies.
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
.then((response) => response.json());
}
return Notifications;
}
// The first step to using the app.
export async function HandleAuthentication(Website, CookieClientID, CookieClientSecret) {
// See if the user is smart enough to put https.
let InstanceData;
if (!Website.toLowerCase().split("://")[0].includes("https")) {
// Quickly check to see if it has something before :// so it doesn't screw the link.
if (Website.toLowerCase().split("://").length > 1) {
Website = "https://" + Website.split("://")[1];
} else {
Website = "https://" + Website;
}
InstanceData = await fetch(Website + "/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.
document.cookie = CookieClientID + "=" + InstanceData.client_id + ";samesite=strict;path=/;expires=9999-01-01;";
document.cookie = CookieClientSecret + "=" + InstanceData.client_secret + ";samesite=strict;path=/;expires=9999-01-01;";
// Now authenticate the app.
document.location.href = Website + "/oauth/authorize?client_id=" + InstanceData.client_id + "&redirect_uri=" + Origin + "&response_type=code&scope=" + ActivityPub.Scopes;
}
// This specific functino goes after HandleAuthentication for when login happens.
export async function GainToken(Website, CookieClientID, CookieClientSecret, CookieAccessToken, CookieTokenType) {
// check if you both have a code and have a current authentication.
if (document.location.href.split("code=").length > 1 && document.cookie.split("; ").find((row) => row.startsWith(CookieClientID + "="))?.split("=") > 1) {
let code = document.location.href.split("code=")[1];
let ClientID = document.cookie.split("; ").find((row) => row.startsWith(CookieClientID + "="))?.split("=")[1];
let ClientSecret = document.cookie.split("; ").find((row) => row.startsWith(CookieClientSecret + "="))?.split("=")[1];
let AuthenticationToken = await fetch(Website + "/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 = CookieAccessToken + "=" + AuthenticationToken.access_token + ";samesite=strict;path=/;expires=9999-01-01;";
document.cookie = CookieTokenType + "=" + AuthenticationToken.token_type + ";samesite=strict;path=/;expires=9999-01-01;";
}
}

0
JS/TumblrAPI.js Normal file
View file

View file

@ -1,4 +1,4 @@
import * as ActivityPub from "./ActivityPub.js";
import * as MastodonAPI from "./MastodonAPI.js";
// GLOBAL VARS
// fuck you. I see why website developers use divs so fucking often.
@ -18,6 +18,8 @@ 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");
// Websites
// Update a timer
function UpdateTime() {
let TimeNow = new Date();
@ -98,7 +100,7 @@ ArrowsButton[0].onclick = (event) => {
PosterContainerUpdate();
}
// ActivityPub integration
// MastodonAPI integration
async function PosterContainerUpdate() {
// Cookies for the public timelines
let LocalCookie = document.cookie.split("; ").find((row) => row.startsWith("Local="))?.split("=")[1];
@ -106,7 +108,7 @@ async function PosterContainerUpdate() {
let RemoteCookie = document.cookie.split("; ").find((row) => row.startsWith("Remote="))?.split("=")[1];
var RemoteTrue = (RemoteCookie === 'true');
let Timeline = await ActivityPub.GetPublicTimeline(LocalTrue, RemoteTrue);
let Timeline = await ActivityPub.GetPublicTimeline(LocalTrue, RemoteTrue, MastodonWebsite);
let Content = [];
let Users = [];
for (let i in Timeline) {

View file

@ -1,47 +1,30 @@
import * as ActivityPub from "./ActivityPub.js";
import * as MastodonAPI from "./MastodonAPI.js";
let LoginButton = document.getElementsByClassName("Login")[0];
let LogoutButton = document.getElementsByClassName("Logout")[0];
let Origin = window.location.origin + "/HTML/mail"
// Mastodon
let MastodonWebsite = "https://wetdry.world";
let MastodonClientID = "mastodon_client_id";
let MastodonClientSecret = "mastodon_client_secret";
let MastodonAccessToken = "mastodon_access_token";
let MastodonTokenType = "mastodon_access_token";
LoginButton.onclick = (event) => {
HandleAuthentication();
MastodonAPI.HandleAuthentication(MastodonWebsite, MastodonClientID, MastodonClientSecret);
}
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;";
}
document.cookie = MastodonAccessToken + "=nothing;" + ";samesite=strict;path=/;expires=0000-01-01;";
document.cookie = MastodonTokenType + "=nothing;" + ";samesite=strict;path=/;expires=0000-01-01;";
console.log("Cleared the access token.");
}
// if an access token is found, login.
function CheckLogin() {
// Check for a token.
if (document.cookie.split("; ").find((row) => row.startsWith("access_token="))?.split("=").length > 1) {
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
// Swap the buttons
LoginButton.remove();
LogoutButton.setAttribute("style", "");
@ -50,54 +33,35 @@ function CheckLogin() {
// 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;
}
let Favorites = 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() {
// 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;
}
let Bookmarks = 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() {
// 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;
}
let Notifications = 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;
}
}
@ -105,8 +69,8 @@ async function PopulateNotifications() {
// Remove traces of "login".
CheckLogin();
// Authentication.
HandleLogin();
// So far: login. TODO: Change this later.
MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
// Populate the areas.
PopulateFavorites();

View file

@ -4,7 +4,7 @@ let RemoteButton = document.getElementsByClassName("Remote")[0];
LocalButton.onclick = (event) => {
// Toggle the cookie
if (document.cookie.split(";").some((item) => item.trim().startsWith("Local="))) {
document.cookie = "Local=true;samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = "Local=true;samesite=strict;path=/;expires=expires=0000-01-01;";
} else {
document.cookie = "Local=true;samesite=strict;path=/;";
}
@ -13,7 +13,7 @@ LocalButton.onclick = (event) => {
RemoteButton.onclick = (event) => {
// Toggle the cookie
if (document.cookie.split(";").some((item) => item.trim().startsWith("Remote="))) {
document.cookie = "Remote=true;samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = "Remote=true;samesite=strict;path=/;expires=expires=0000-01-01;";
} else {
document.cookie = "Remote=true;samesite=strict;path=/;";
}