Made it more explicit that I am not using ActivityPub
This commit is contained in:
parent
32065edbd5
commit
2a20fd544e
7 changed files with 145 additions and 98 deletions
|
@ -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
0
JS/BlueskyAPI.js
Normal file
101
JS/MastodonAPI.js
Normal file
101
JS/MastodonAPI.js
Normal 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
0
JS/TumblrAPI.js
Normal file
|
@ -1,4 +1,4 @@
|
||||||
import * as ActivityPub from "./ActivityPub.js";
|
import * as MastodonAPI from "./MastodonAPI.js";
|
||||||
|
|
||||||
// GLOBAL VARS
|
// GLOBAL VARS
|
||||||
// fuck you. I see why website developers use divs so fucking often.
|
// 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 WarningClick = new Audio("Audio/button-pressed-38129.mp3");
|
||||||
const BackgroundMusic = new Audio("Audio/soft-piano-music-312509.mp3");
|
const BackgroundMusic = new Audio("Audio/soft-piano-music-312509.mp3");
|
||||||
|
|
||||||
|
// Websites
|
||||||
|
|
||||||
// Update a timer
|
// Update a timer
|
||||||
function UpdateTime() {
|
function UpdateTime() {
|
||||||
let TimeNow = new Date();
|
let TimeNow = new Date();
|
||||||
|
@ -98,7 +100,7 @@ ArrowsButton[0].onclick = (event) => {
|
||||||
PosterContainerUpdate();
|
PosterContainerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActivityPub integration
|
// MastodonAPI integration
|
||||||
async function PosterContainerUpdate() {
|
async function PosterContainerUpdate() {
|
||||||
// Cookies for the public timelines
|
// Cookies for the public timelines
|
||||||
let LocalCookie = document.cookie.split("; ").find((row) => row.startsWith("Local="))?.split("=")[1];
|
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];
|
let RemoteCookie = document.cookie.split("; ").find((row) => row.startsWith("Remote="))?.split("=")[1];
|
||||||
var RemoteTrue = (RemoteCookie === 'true');
|
var RemoteTrue = (RemoteCookie === 'true');
|
||||||
|
|
||||||
let Timeline = await ActivityPub.GetPublicTimeline(LocalTrue, RemoteTrue);
|
let Timeline = await ActivityPub.GetPublicTimeline(LocalTrue, RemoteTrue, MastodonWebsite);
|
||||||
let Content = [];
|
let Content = [];
|
||||||
let Users = [];
|
let Users = [];
|
||||||
for (let i in Timeline) {
|
for (let i in Timeline) {
|
||||||
|
|
80
JS/mail.js
80
JS/mail.js
|
@ -1,47 +1,30 @@
|
||||||
import * as ActivityPub from "./ActivityPub.js";
|
import * as MastodonAPI from "./MastodonAPI.js";
|
||||||
|
|
||||||
let LoginButton = document.getElementsByClassName("Login")[0];
|
let LoginButton = document.getElementsByClassName("Login")[0];
|
||||||
let LogoutButton = document.getElementsByClassName("Logout")[0];
|
let LogoutButton = document.getElementsByClassName("Logout")[0];
|
||||||
let Origin = window.location.origin + "/HTML/mail"
|
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) => {
|
LoginButton.onclick = (event) => {
|
||||||
HandleAuthentication();
|
MastodonAPI.HandleAuthentication(MastodonWebsite, MastodonClientID, MastodonClientSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogoutButton.onclick = (event) => {
|
LogoutButton.onclick = (event) => {
|
||||||
console.log("Does nothing so far.");
|
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.");
|
||||||
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;";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if an access token is found, login.
|
||||||
function CheckLogin() {
|
function CheckLogin() {
|
||||||
// Check for a token.
|
// 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
|
// Swap the buttons
|
||||||
LoginButton.remove();
|
LoginButton.remove();
|
||||||
LogoutButton.setAttribute("style", "");
|
LogoutButton.setAttribute("style", "");
|
||||||
|
@ -50,13 +33,8 @@ function CheckLogin() {
|
||||||
|
|
||||||
// Below is the thing it populates if you login.
|
// Below is the thing it populates if you login.
|
||||||
async function PopulateFavorites() {
|
async function PopulateFavorites() {
|
||||||
// Check for a token.
|
let Favorites = MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||||
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];
|
let FavoritesArea = document.getElementsByClassName("Favorites")[0];
|
||||||
// Populate the favorites area.
|
// Populate the favorites area.
|
||||||
for (let i in Favorites) {
|
for (let i in Favorites) {
|
||||||
|
@ -64,16 +42,10 @@ async function PopulateFavorites() {
|
||||||
FavoritesArea.getElementsByClassName("Favorite")[i].innerHTML = Favorites[i].content;
|
FavoritesArea.getElementsByClassName("Favorite")[i].innerHTML = Favorites[i].content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function PopulateBookmarks() {
|
async function PopulateBookmarks() {
|
||||||
// Check for a token.
|
let Bookmarks = MastodonAPI.GetBookmarks(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||||
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];
|
let BookmarksArea = document.getElementsByClassName("Bookmarks")[0];
|
||||||
// Populate the Bookmarks area.
|
// Populate the Bookmarks area.
|
||||||
for (let i in Bookmarks) {
|
for (let i in Bookmarks) {
|
||||||
|
@ -81,17 +53,10 @@ async function PopulateBookmarks() {
|
||||||
BookmarksArea.getElementsByClassName("Bookmark")[i].innerHTML = Bookmarks[i].content;
|
BookmarksArea.getElementsByClassName("Bookmark")[i].innerHTML = Bookmarks[i].content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function PopulateNotifications() {
|
async function PopulateNotifications() {
|
||||||
// Check for a token.
|
let Notifications = MastodonAPI.GetNotifications(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||||
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];
|
let NotificationsArea = document.getElementsByClassName("Notifications")[0];
|
||||||
// Populate the Conversations area.
|
// Populate the Conversations area.
|
||||||
for (let i in Notifications) {
|
for (let i in Notifications) {
|
||||||
|
@ -99,14 +64,13 @@ async function PopulateNotifications() {
|
||||||
NotificationsArea.getElementsByClassName("Notification")[i].innerHTML = Notifications[i].status.content;
|
NotificationsArea.getElementsByClassName("Notification")[i].innerHTML = Notifications[i].status.content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Runs on website start.
|
// Runs on website start.
|
||||||
// Remove traces of "login".
|
// Remove traces of "login".
|
||||||
CheckLogin();
|
CheckLogin();
|
||||||
|
|
||||||
// Authentication.
|
// So far: login. TODO: Change this later.
|
||||||
HandleLogin();
|
MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
|
||||||
|
|
||||||
// Populate the areas.
|
// Populate the areas.
|
||||||
PopulateFavorites();
|
PopulateFavorites();
|
||||||
|
|
|
@ -4,7 +4,7 @@ let RemoteButton = document.getElementsByClassName("Remote")[0];
|
||||||
LocalButton.onclick = (event) => {
|
LocalButton.onclick = (event) => {
|
||||||
// Toggle the cookie
|
// Toggle the cookie
|
||||||
if (document.cookie.split(";").some((item) => item.trim().startsWith("Local="))) {
|
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 {
|
} else {
|
||||||
document.cookie = "Local=true;samesite=strict;path=/;";
|
document.cookie = "Local=true;samesite=strict;path=/;";
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ LocalButton.onclick = (event) => {
|
||||||
RemoteButton.onclick = (event) => {
|
RemoteButton.onclick = (event) => {
|
||||||
// Toggle the cookie
|
// Toggle the cookie
|
||||||
if (document.cookie.split(";").some((item) => item.trim().startsWith("Remote="))) {
|
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 {
|
} else {
|
||||||
document.cookie = "Remote=true;samesite=strict;path=/;";
|
document.cookie = "Remote=true;samesite=strict;path=/;";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue