diff --git a/CSS/index.css b/CSS/index.css index 0256dc6..ee4f788 100644 --- a/CSS/index.css +++ b/CSS/index.css @@ -205,6 +205,13 @@ html { border-width: 1px; } +.Posting { + border-style: solid; + border-width: 1px; + + margin-right: 5%; +} + .MainFooter { display: flex; margin-top: 75vh; diff --git a/CSS/post.css b/CSS/post.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CSS/post.css @@ -0,0 +1 @@ + diff --git a/CSS/setting.css b/CSS/setting.css new file mode 100644 index 0000000..e69de29 diff --git a/HTML/post.html b/HTML/post.html new file mode 100644 index 0000000..00490d1 --- /dev/null +++ b/HTML/post.html @@ -0,0 +1,21 @@ + + + + The Fediverse + + + + + + + + + +
+

Post

+ +

POST!

+
+

Back

+ + diff --git a/HTML/setting.html b/HTML/setting.html index b99464a..8c9c08e 100644 --- a/HTML/setting.html +++ b/HTML/setting.html @@ -4,7 +4,7 @@ The Fediverse - + @@ -17,10 +17,10 @@

Toggle Local

Toggle Remote

Login to Mastodon

- +

Login to Bluesky

- +

OK

diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index b221667..7adb8eb 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -156,7 +156,7 @@ export async function GainTokens() { let WellKnown = await GetPDSWellKnown(); // Check to see if something's a miss... - if ((document.location.href.split("state=").length > 1 && document.location.href.split("iss=").length > 1 && document.location.href.split("code=").length > 1) && Cookie.IsCookieReal(Cookie.BlueskyPKCEVeriferCookie)) { + if ((document.location.href.split("state=").length > 1 && document.location.href.split("iss=").length > 1 && document.location.href.split("code=").length > 1) && Cookie.IsCookieReal(Cookie.BlueskyPKCEVeriferCookie) && !(Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie))) { // Create varaibles, be aware of waits because of internet. let DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint); let code = document.location.href.split("code=")[1]; diff --git a/JS/Cookies.js b/JS/Cookies.js index ce5b587..800013c 100644 --- a/JS/Cookies.js +++ b/JS/Cookies.js @@ -1,6 +1,6 @@ // STRINGS TODO: make sure to seperate stuff that a user will want to input. Ex: MastodonWebsiteName, BlueskyPDS, etc. // Mastodon -export const MastodonWebsiteName = "https://wetdry.world"; +export const MastodonWebsiteName = "mastodon_website"; export const MastodonClientIDName = "mastodon_client_id"; export const MastodonClientSecretName = "mastodon_client_secret"; export const MastodonAccessTokenName = "mastodon_access_token"; @@ -22,6 +22,7 @@ export const TumblrWebsiteName = "https://www.tumblr.com"; // COOKIES TODO: person inputted stuff (like MastodonWebsiteName) should be implemented. // Mastodon +export const MastodonWebsiteCookie = GetCookie(MastodonWebsiteName); export const MastodonClientIDCookie = GetCookie(MastodonClientIDName); export const MastodonClientSecretCookie = GetCookie(MastodonClientSecretName); export const MastodonAccessTokenCookie = GetCookie(MastodonAccessTokenName); diff --git a/JS/MastodonAPI.js b/JS/MastodonAPI.js index fb84d78..95d20d7 100644 --- a/JS/MastodonAPI.js +++ b/JS/MastodonAPI.js @@ -4,6 +4,7 @@ export const Scopes = "read write follow push"; // Gets the public timeline. export async function GetPublicTimeline(Local = false, Remote = false, Website) { + // Cookies can be found in `setting.js` let Timeline; if (Local == true && Remote == true) { console.error("Don't set both Local and Remote timelines to true."); @@ -24,10 +25,11 @@ export async function GetPublicTimeline(Local = false, Remote = false, Website) } // Gets the favorites of a user that you have access to. -export async function GetFavorites(Website) { +export async function GetFavorites() { let Favorites; // Check for a token. if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + let Website = Cookie.MastodonWebsiteCookie; // Get the varaibles that are stored in cookies. Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) .then((response) => response.json()); @@ -36,10 +38,11 @@ export async function GetFavorites(Website) { } // Gets the bookmarks of a user that you have access to. -export async function GetBookmarks(Website) { +export async function GetBookmarks() { let Bookmarks; // Check for a token. if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + let Website = Cookie.MastodonWebsiteCookie; // Get the varaibles that are stored in cookies. Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) .then((response) => response.json()); @@ -48,10 +51,11 @@ export async function GetBookmarks(Website) { } // Gets the notifications of a user that you have access to. -export async function GetNotifications(Website) { +export async function GetNotifications() { let Notifications; // Check for a token. if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + let Website = Cookie.MastodonWebsiteCookie; // Get the varaibles that are stored in cookies and then input it. Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) .then((response) => response.json()); @@ -59,6 +63,16 @@ export async function GetNotifications(Website) { return Notifications; } +// Make a status +export async function CreateStatus(Text) { + // Check for a token + if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + let Website = Cookie.MastodonWebsiteCookie; + return await fetch(Website + "/api/v1/statuses?status=" + Text , {method: "POST", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) + .then((response) => response.json()); + } +} + // The first step to using the app. export async function HandleAuthentication(Website) { // See if the user is smart enough to put https. @@ -69,6 +83,8 @@ export async function HandleAuthentication(Website) { } else { Website = "https://" + Website; } + // Save the website + Cookie.InputCookie(Cookie.MastodonWebsiteName, Website); // Registering the app. InstanceData = await fetch(Website + "/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + document.location.href + "&scopes=" + Scopes, {method: "POST"}) .then((response) => response.json()); @@ -80,14 +96,16 @@ export async function HandleAuthentication(Website) { } // This specific functino goes after HandleAuthentication for when login happens. -export async function GainToken(Website) { +export async function GainToken() { // check if you both have a code and have a current authentication. - if (document.location.href.split("code=").length > 1 && Cookie.IsCookieReal(Cookie.MastodonClientIDCookie)) { + if (document.location.href.split("code=").length > 1 && Cookie.IsCookieReal(Cookie.MastodonClientIDCookie) && !(Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie))) { + // Get some vars. let code = document.location.href.split("code=")[1]; - + let Website = Cookie.MastodonWebsiteCookie; + // Authenticate. let AuthenticationToken = await fetch(Website + "/oauth/token?client_id=" + Cookie.MastodonClientIDCookie + "&client_secret=" + Cookie.MastodonClientSecretCookie + "&redirect_uri=" + document.location.href + "&grant_type=authorization_code&code=" + code, {method: "POST"}) .then((response) => response.json()); - // Cookify These + // Cookify These. Cookie.InputCookie(Cookie.MastodonAccessTokenName, AuthenticationToken.access_token); Cookie.InputCookie(Cookie.MastodonTokenTypeName, AuthenticationToken.token_type); } diff --git a/JS/TumblrAPI.js b/JS/TumblrAPI.js index e69de29..79a00a1 100644 --- a/JS/TumblrAPI.js +++ b/JS/TumblrAPI.js @@ -0,0 +1 @@ +import * as Cookie from "./Cookies.js"; diff --git a/JS/index.js b/JS/index.js index 9f7cd45..aadf229 100644 --- a/JS/index.js +++ b/JS/index.js @@ -15,6 +15,7 @@ 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"); @@ -108,8 +109,13 @@ async function PosterContainerUpdate() { var LocalTrue = (LocalCookie === "true"); let RemoteCookie = Cookie.GetCookie("Remote"); var RemoteTrue = (RemoteCookie === "true"); + let Website = Cookie.MastodonWebsiteCookie; - let Timeline = await MastodonAPI.GetPublicTimeline(LocalTrue, RemoteTrue, Cookie.MastodonWebsiteName); + if (!(Cookie.IsCookieReal(Cookie.MastodonWebsiteCookie))) { + Website = "https://wetdry.world"; + } + + let Timeline = await MastodonAPI.GetPublicTimeline(LocalTrue, RemoteTrue, Website); let Content = []; let Users = []; for (let i in Timeline) { @@ -128,7 +134,12 @@ SettingButton.onclick = (event) => { window.location.href = "./HTML/setting.html"; } -// Open the notifs, private message, favorites, bookmarks +// 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"; +} diff --git a/JS/mail.js b/JS/mail.js index 313839d..2ba773f 100644 --- a/JS/mail.js +++ b/JS/mail.js @@ -5,7 +5,7 @@ import * as Cookie from "./Cookies.js"; // Below is the thing it populates if you login. async function PopulateFavorites() { - let Favorites = await MastodonAPI.GetFavorites(Cookie.MastodonWebsiteName); + let Favorites = await MastodonAPI.GetFavorites(); let FavoritesArea = document.getElementsByClassName("Favorites")[0]; // Populate the favorites area. @@ -16,7 +16,7 @@ async function PopulateFavorites() { } async function PopulateBookmarks() { - let Bookmarks = await MastodonAPI.GetBookmarks(Cookie.MastodonWebsiteName); + let Bookmarks = await MastodonAPI.GetBookmarks(); let BookmarksArea = document.getElementsByClassName("Bookmarks")[0]; // Populate the Bookmarks area. @@ -27,7 +27,7 @@ async function PopulateBookmarks() { } async function PopulateNotifications() { - let Notifications = await MastodonAPI.GetNotifications(Cookie.MastodonWebsiteName); + let Notifications = await MastodonAPI.GetNotifications(); let NotificationsArea = document.getElementsByClassName("Notifications")[0]; // Populate the Conversations area. diff --git a/JS/post.js b/JS/post.js new file mode 100644 index 0000000..78f4a80 --- /dev/null +++ b/JS/post.js @@ -0,0 +1,25 @@ +import * as MastodonAPI from "./MastodonAPI.js"; +import * as BlueskyAPI from "./BlueskyAPI.js"; +import * as TumblrAPI from "./TumblrAPI.js"; +import * as Cookie from "./Cookies.js"; + +// Elements. +let PostButton = document.getElementsByClassName("button")[0]; +let InputArea = document.getElementsByClassName("text")[0]; + +// Clicking the beeg POST button. +PostButton.onclick = (event) => { + Post(); +} + +async function Post() { + let Text = InputArea.value; + // Mastodon posting. + if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + MastodonAPI.CreateStatus(Text); + } + // Bluesky posting. + if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) { + + } +} diff --git a/JS/setting.js b/JS/setting.js index 4a8abd3..1bedf09 100644 --- a/JS/setting.js +++ b/JS/setting.js @@ -14,6 +14,9 @@ let BlueskyLoginButton = document.getElementsByClassName("Login Bluesky")[0]; let BlueskyWebInput = document.getElementsByClassName("WebInput Bluesky")[0]; let BlueskyLogoutButton = document.getElementsByClassName("Logout Bluesky")[0]; +// original link +let Origin = location.origin + "/HTML/setting.html" + // Change weather the timelines are public or remote LocalButton.onclick = (event) => { // Toggle the cookie @@ -36,8 +39,9 @@ RemoteButton.onclick = (event) => { // Mastodon buttons // Login MastodonLoginButton.onclick = (event) => { - if (MastodonWebInput != "") { - MastodonAPI.HandleAuthentication(Cookie.MastodonWebsiteName); + if (MastodonWebInput.value != "") { + let text = MastodonWebInput.value + MastodonAPI.HandleAuthentication(text); } } @@ -47,13 +51,13 @@ MastodonLogoutButton.onclick = (event) => { Cookie.ExpireCookie(Cookie.MastodonClientSecretName); Cookie.ExpireCookie(Cookie.MastodonAccessTokenName); Cookie.ExpireCookie(Cookie.MastodonTokenTypeName); - document.location.href = document.location.href; + document.location.href = Origin; } // Bluesky Buttons // Login BlueskyLoginButton.onclick = (event) => { - if (BlueskyWebInput != "") { + if (BlueskyWebInput.value != "") { BlueskyAPI.HandleAuthorization(); } } @@ -67,7 +71,7 @@ BlueskyLogoutButton.onclick = (event) => { Cookie.ExpireCookie(Cookie.BlueskyRefreshTokenName); Cookie.ExpireCookie(Cookie.BlueskyPublicKeyName); Cookie.ExpireCookie(Cookie.BlueskyPrivateKeyName); - document.location.href = document.location.href; + document.location.href = Origin; } // if an access token is found, login. @@ -80,7 +84,7 @@ async function CheckLogin() { MastodonLogoutButton.setAttribute("style", ""); } else { // Auto log in - MastodonAPI.GainToken(Cookie.MastodonWebsiteName); + await MastodonAPI.GainToken(Cookie.MastodonWebsiteName); } // Check for a bluesky token. if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) { @@ -90,7 +94,7 @@ async function CheckLogin() { BlueskyLogoutButton.setAttribute("style", ""); } else { // Auto log in - BlueskyAPI.GainTokens(); + await BlueskyAPI.GainTokens(); } } diff --git a/index.html b/index.html index d4fdf5b..0489f4c 100644 --- a/index.html +++ b/index.html @@ -292,6 +292,7 @@