diff --git a/CSS/expanded.css b/CSS/expanded.css index e69de29..8715043 100644 --- a/CSS/expanded.css +++ b/CSS/expanded.css @@ -0,0 +1,27 @@ +/* HTML items */ +img { + border-style: solid; + border-radius: 1%; + + width: 45%; +} + +/* Classes */ +.Handle { + +} + +.Origin { + +} + +.PostText { + +} + +.Images { + display: flex; + justify-content: center; + flex-wrap: wrap; + +} diff --git a/CSS/index.css b/CSS/index.css index 47d879f..231b039 100644 --- a/CSS/index.css +++ b/CSS/index.css @@ -54,6 +54,7 @@ html { overflow-x: hidden; + overflow-y: hidden; } /* Classes for the warning section*/ diff --git a/HTML/expanded.html b/HTML/expanded.html index 403a957..76ce64e 100644 --- a/HTML/expanded.html +++ b/HTML/expanded.html @@ -3,6 +3,7 @@ The Fediverse + @@ -13,10 +14,16 @@

-

Bsky/Mastodon (TODO)

-

-

Image here if it is a thing (TODO)

-

Back

+

+

+
+
+
+

Favorite!

+

Boost!

+

Reply!

+
+

Back

diff --git a/HTML/mail.html b/HTML/mail.html index 786e0f6..d9417a7 100644 --- a/HTML/mail.html +++ b/HTML/mail.html @@ -3,6 +3,7 @@ The Fediverse + @@ -16,7 +17,7 @@

Mail

-

Back

+

Back

diff --git a/HTML/post.html b/HTML/post.html index 44a3b83..612c6e9 100644 --- a/HTML/post.html +++ b/HTML/post.html @@ -3,6 +3,7 @@ The Fediverse + @@ -24,6 +25,6 @@

POST!

-

Back

+

Back

diff --git a/HTML/setting.html b/HTML/setting.html index 4e71edd..51f38ed 100644 --- a/HTML/setting.html +++ b/HTML/setting.html @@ -3,6 +3,7 @@ The Fediverse + diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index 22cca87..2d18b84 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -26,40 +26,48 @@ export async function GetTimeline(Cursor) { return body; } -export async function CreatePost(DID, Text) { +export async function GetPosts(URIs) { if (localStorage.getItem(Variables.BlueskyAccessToken) == null) { console.log("No access token!"); return ""; } let PDS = localStorage.getItem(Variables.BlueskyPDS); - let Json = { - "$type": "app.bsky.feed.post", - "text": Text, - "createdAt": new Date(Date.now()).toISOString() - } - let RequestBody = { - "repo": DID, - "collection": "app.bsky.feed.post", - "record": Json - } - let DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); + let DPoP = await ClientDPoPPDS("GET", PDS + "/xrpc/app.bsky.feed.getPosts?uris=" + URIs); + let request = fetch(PDS + "/xrpc/app.bsky.feed.getPosts?uris=" + URIs, { method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); let body = await request.then((response) => response.json()); let status = await request.then((response) => response.status); let header = await request.then((response) => response.headers.get("dpop-nonce")); if (status == 401) { await HandleError(body, header); - body = await CreatePost(DID, Text); + body = await GetPosts(URIs); } - if (status == 400) { + return body; +} + +// Get a blob (like an image or video). Authentication need not apply. +export async function GetBlob(DID, CID) { + let PDS = localStorage.getItem(Variables.BlueskyPDS); + let request = fetch("https://bsky.social/xrpc/com.atproto.sync.getBlob?did=" + DID + "&cid=" + CID, {method: "GET"}); + let body = await request.then((response) => response.json()); + return body; +} + +export async function CreatePost(DID, Text) { + if (localStorage.getItem(Variables.BlueskyAccessToken) == null) { + console.log("No access token!"); + return ""; + } + let Record = { + "$type": "app.bsky.feed.post", + "text": Text, + "createdAt": new Date(Date.now()).toISOString() + } + let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined); + if (body.hasOwnProperty("error") && body.error == "InvalidRequest") { let matches = body.message.match(/(\d+)/); - Json.text = Text.slice(0, matches[0] - 1); - RequestBody.record = Json; - DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); - body = await request.then((response) => response.json()); - status = await request.then((response) => response.status); + Record.text = Text.slice(0, matches[0] - 1); + body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined); await CreateReplyPost(DID, Text.slice(matches[0] - 1, Text.length - 1), body, body); } return body; @@ -70,45 +78,26 @@ export async function CreateReplyPost(DID, Text, ReplyID, RootID) { console.log("No access token!"); return ""; } - - let PDS = localStorage.getItem(Variables.BlueskyPDS); - let Json = { + let Record = { "$type": "app.bsky.feed.post", "text": Text, "createdAt": new Date(Date.now()).toISOString(), "reply": { - "root": { + "parent": { "uri": ReplyID.uri, "cid": ReplyID.cid }, - "parent": { + "root": { "uri": RootID.uri, "cid": RootID.cid } } } - let RequestBody = { - "repo": DID, - "collection": "app.bsky.feed.post", - "record": Json - } - let DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); - let body = await request.then((response) => response.json()); - let status = await request.then((response) => response.status); - let header = await request.then((response) => response.headers.get("dpop-nonce")); - if (status == 401) { - await HandleError(body, header); - body = await CreatePost(DID, Text); - } - if (status == 400) { + let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined); + if (body.hasOwnProperty("error") && body.error == "InvalidRequest") { let matches = body.message.match(/(\d+)/); - Json.text = Text.slice(0, matches[0] - 1); - RequestBody.record = Json; - let DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); - let body = await request.then((response) => response.json()); - let status = await request.then((response) => response.status); + Record.text = Text.slice(0, matches[0] - 1); + body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined); await CreateReplyPost(DID, Text.slice(matches[0] - 1, Text.length - 1), body, RootID); } return body; @@ -119,28 +108,119 @@ export async function SetThreadGate(DID, Post, VisibilitySettings) { console.log("No access token!"); return ""; } - - let PDS = localStorage.getItem(Variables.BlueskyPDS); - let Json = { + let Record = { "$type": "app.bsky.feed.threadgate", "post": Post, "allow": VisibilitySettings, "createdAt": new Date(Date.now()).toISOString() } - let RequestBody = { - "repo": DID, - "collection": "app.bsky.feed.threadgate", - "record": Json, - "rkey": Post.split("/")[Post.split("/").length - 1] + let body = CreateRecord(DID, "app.bsky.feed.threadgate", Record, undefined); + return body; +} + +export async function SendLike(DID, RefURI, RefCID) { + if (localStorage.getItem(Variables.BlueskyAccessToken) == null) { + console.log("No access token!"); + return ""; } - let DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); + let StrongRef = { + "$type": "com.atproto.repo.strongRef", + "uri": RefURI, + "cid": RefCID + } + let Record = { + "$type": "app.bsky.feed.like", + "subject": StrongRef, + "createdAt": new Date(Date.now()).toISOString() + } + let body = await GetRecord(DID, "app.bsky.feed.like", RefURI.split("/")[RefURI.split("/").length - 1]); + // We might have a record. If we do, delete the thing. If we don't, create the thing. + if (body.hasOwnProperty("error") && body.error == "RecordNotFound") { + body = await CreateRecord(DID, "app.bsky.feed.like", Record, RefURI.split("/")[RefURI.split("/").length - 1]); + } else { + body = await DeleteRecord(DID, "app.bsky.feed.like", RefURI.split("/")[RefURI.split("/").length - 1]); + } + return body; +} + +export async function SendRepost(DID, RefURI, RefCID) { + if (localStorage.getItem(Variables.BlueskyAccessToken) == null) { + console.log("No access token!"); + return ""; + } + let StrongRef = { + "$type": "com.atproto.repo.strongRef", + "uri": RefURI, + "cid": RefCID + } + let Record = { + "$type": "app.bsky.feed.repost", + "subject": StrongRef, + "createdAt": new Date(Date.now()).toISOString() + } + let body = await GetRecord(DID, "app.bsky.feed.repost", RefURI.split("/")[RefURI.split("/").length - 1]); + // We might have a record. If we do, delete the thing. If we don't, create the thing. + if (body.hasOwnProperty("error") && body.error == "RecordNotFound") { + body = await CreateRecord(DID, "app.bsky.feed.repost", Record, RefURI.split("/")[RefURI.split("/").length - 1]); + } else { + body = await DeleteRecord(DID, "app.bsky.feed.repost", RefURI.split("/")[RefURI.split("/").length - 1]); + } + return body; +} + +export async function GetRecord(Repo, Collection, RKey) { + let RequestBody = { + "repo": Repo, + "collection": Collection, + "rkey": RKey + } + let DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.getRecord?repo=" + Repo + "&collection=" + Collection + "&rkey=" + RKey); + let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.getRecord?repo=" + Repo + "&collection=" + Collection + "&rkey=" + RKey, { method: "GET", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); let body = await request.then((response) => response.json()); let status = await request.then((response) => response.status); let header = await request.then((response) => response.headers.get("dpop-nonce")); if (status == 401) { await HandleError(body, header); - body = await SetThreadGate(DID, Post, VisibilitySettings); + body = await DeleteRecord(Repo, Collection, RKey); + } + return body; +} + +export async function CreateRecord(Repo, Collection, Record, RKey) { + let RequestBody = { + "repo": Repo, + "collection": Collection, + "record": Record + } + if (RKey != undefined) { + RequestBody.rkey = RKey; + } + let DPoP = await ClientDPoPPDS("POST", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.createRecord"); + let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); + let body = await request.then((response) => response.json()); + let status = await request.then((response) => response.status); + let header = await request.then((response) => response.headers.get("dpop-nonce")); + if (status == 401) { + await HandleError(body, header); + body = await CreateRecord(Repo, Collection, Record, RKey); + } + return body; +} + +export async function DeleteRecord(Repo, Collection, RKey) { + let RequestBody = { + "repo": Repo, + "collection": Collection, + "rkey": RKey + } + let DPoP = await ClientDPoPPDS("POST", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.deleteRecord"); + let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.deleteRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}}); + let body = await request.then((response) => response.json()); + let status = await request.then((response) => response.status); + let header = await request.then((response) => response.headers.get("dpop-nonce")); + if (status == 401) { + await HandleError(body, header); + body = await DeleteRecord(Repo, Collection, RKey); } return body; } diff --git a/JS/MastodonAPI.js b/JS/MastodonAPI.js index 887f228..4950e41 100644 --- a/JS/MastodonAPI.js +++ b/JS/MastodonAPI.js @@ -77,6 +77,17 @@ export async function GetNotifications() { .then((response) => response.json()); } +export async function GetStatus(ID) { + if (localStorage.getItem(Variables.MastodonAccessToken) == null) { + console.log("No access token!"); + return ""; + } + let Website = localStorage.getItem(Variables.MastodonWebsite); + // Get the varaibles that are stored in Variables and then input it. + return await fetch(Website + "/api/v1/statuses/" + ID, {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}) + .then((response) => response.json()); +} + // Make a status export async function CreateStatus(Text, Visibility = "public") { if (localStorage.getItem(Variables.MastodonAccessToken) == null) { @@ -93,7 +104,6 @@ export async function CreateStatus(Text, Visibility = "public") { // This is in case you went over the characters. if (status == 422) { let matches = body.error.match(/(\d+)/); - console.log(matches); request = fetch(Website + "/api/v1/statuses?status=" + Text.slice(0, matches[0] - 1) + "&visibility=" + Visibility, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}); body = await request.then((response) => response.json()); await CreateReplyStatus(Text.slice(matches[0] - 1, Text.length - 1), Visibility, body.id); @@ -123,6 +133,36 @@ export async function CreateReplyStatus(Text, Visibility = "public", ReplyID) { return body; } +export async function SendFavorite(ID, IsFavorited) { + if (localStorage.getItem(Variables.MastodonAccessToken) == null) { + console.log("No access token!"); + return ""; + } + let Website = localStorage.getItem(Variables.MastodonWebsite); + if (IsFavorited == false) { + return await fetch(Website + "/api/v1/statuses/" + ID + "/favourite", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}) + .then((response) => response.json()); + } else { + return await fetch(Website + "/api/v1/statuses/" + ID + "/unfavourite", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}) + .then((response) => response.json()); + } +} + +export async function SendReblog(ID, IsReblogged) { + if (localStorage.getItem(Variables.MastodonAccessToken) == null) { + console.log("No access token!"); + return ""; + } + let Website = localStorage.getItem(Variables.MastodonWebsite); + if (IsReblogged == false) { + return await fetch(Website + "/api/v1/statuses/" + ID + "/reblog", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}) + .then((response) => response.json()); + } else { + return await fetch(Website + "/api/v1/statuses/" + ID + "/unreblog", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}}) + .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. diff --git a/JS/expanded.js b/JS/expanded.js index c4838cd..497f650 100644 --- a/JS/expanded.js +++ b/JS/expanded.js @@ -1,5 +1,107 @@ -let content = decodeURI(document.location.href.split("content=")[1]); -let username = decodeURI(document.location.href.split("username=")[1].split("&content")[0]); +import * as MastodonAPI from "./MastodonAPI.js"; +import * as BlueskyAPI from "./BlueskyAPI.js"; +import * as TumblrAPI from "./TumblrAPI.js"; +import * as Variables from "./Variables.js"; -document.getElementsByClassName("Handle")[0].innerHTML = username; -document.getElementsByClassName("DetailedText")[0].innerHTML = content; +// Buttons +let Favorite = document.getElementsByClassName("Favorite")[0]; +let Boost = document.getElementsByClassName("Boost")[0]; +let Reply = document.getElementsByClassName("Reply")[0]; + +let FavoriteFlipper = false; +let BoostFlipper = false; + +// Variables +let website = document.location.href.split("website=")[1]; +let post = JSON.parse(localStorage.getItem("post")); + +document.getElementsByClassName("Origin")[0].innerHTML = website; +GetPost(); + +// Button stuff +Favorite.onclick = (event) => { + if (website == "Mastodon") { + MastodonAPI.SendFavorite(post.id, post.favourited); + } else if (website == "Bluesky") { + BlueskyAPI.SendLike(localStorage.getItem(Variables.BlueskyDID), post.post.uri, post.post.cid); + } + SetFavorite(); +} + +Boost.onclick = (event) => { + if (website == "Mastodon") { + MastodonAPI.SendReblog(post.id, post.reblogged); + } else if (website == "Bluesky") { + BlueskyAPI.SendRepost(localStorage.getItem(Variables.BlueskyDID), post.post.uri, post.post.cid); + } + SetBoost(); +} + +Reply.onclick = (event) => { + window.location.href = "../../HTML/post.html?website=" + website; +} + +// Functions and things. +async function GetPost() { + if (website == "Mastodon") { + // Check for a reblog. + if (post.reblog != null) { + document.getElementsByClassName("PostText")[0].innerHTML = post.reblog.content; + document.getElementsByClassName("Handle")[0].innerHTML = post.reblog.account.username + " ( R: " + post.account.username + " )"; + } else { + document.getElementsByClassName("PostText")[0].innerHTML = post.content; + document.getElementsByClassName("Handle")[0].innerHTML = post.account.username; + } + // Show the image if it exists. + if (post.media_attachments.length != 0) { + for (let i of post.media_attachments) { + document.getElementsByClassName("Images")[0].innerHTML = document.getElementsByClassName("Images")[0].innerHTML + "" + i.description + ""; + } + } + // Update the post to see if there is new information. + post = await MastodonAPI.GetStatus(post.id); + // Set the texts. + FavoriteFlipper = !(post.favourite); + BoostFlipper = !(post.reblogged); + SetFavorite(); + SetBoost(); + } else if (website == "Bluesky") { + // Check for a reblog. + if (post.hasOwnProperty("reason") && post.reason.$type == "app.bsky.feed.defs#reasonRepost") { + document.getElementsByClassName("PostText")[0].innerHTML = post.post.record.text; + document.getElementsByClassName("Handle")[0].innerHTML = post.post.author.handle + " ( R: " + post.reason.by.handle + " )"; + } else { + document.getElementsByClassName("PostText")[0].innerHTML = post.post.record.text; + document.getElementsByClassName("Handle")[0].innerHTML = post.post.author.handle; + } + // Show the image if it exists. + if (post.post.record.hasOwnProperty("embed") && post.post.record.embed.$type == "app.bsky.embed.images") { + for (let i of post.post.embed.images) { + document.getElementsByClassName("Images")[0].innerHTML = document.getElementsByClassName("Images")[0].innerHTML + "" + i.alt + ""; + } + } + // We don't need to update the post with new information. The repos are seperate. + // Set the texts. + // TODO! + } else { + document.getElementsByClassName("PostText")[0].innerHTML = "Nothing to load."; + } +} + +function SetFavorite() { + FavoriteFlipper = !(FavoriteFlipper); + if (FavoriteFlipper == false) { + Favorite.innerHTML = "Favorite!"; + } else { + Favorite.innerHTML = "Unfavorite..."; + } +} + +function SetBoost() { + BoostFlipper = !(BoostFlipper); + if (BoostFlipper == false) { + Boost.innerHTML = "Boost!"; + } else { + Boost.innerHTML = "Unboost..."; + } +} diff --git a/JS/index.js b/JS/index.js index d19b711..f8e93f2 100644 --- a/JS/index.js +++ b/JS/index.js @@ -101,27 +101,45 @@ ArrowsButton[0].onclick = (event) => { } } -for (let i of ClickableContainers) { - i.onclick = (event) => { - let content = i.getElementsByClassName("PostContent")[0].innerHTML - let username = i.getElementsByClassName("Username")[0].innerHTML - // Save some info - window.location.href = "./HTML/expanded.html?username=" + username + "&content=" + content; - } -} - // These numbers are here so you don't go back. let MastodonLoadedFeed = []; let BlueskyLoadedFeed = []; let CurrentThing = 0; +let WebsiteAPIType = []; + +let Mastodon = true; +let Bluesky = true; + +// This will allow you to click on a post and get an "expended" version of that post. +for (let i of ClickableContainers) { + i.onclick = (event) => { + let number = parseInt(i.getAttribute("number")); + let post; + let website; + // Roundabout way of doing things. Very funny. + website = WebsiteAPIType[number]; + if (WebsiteAPIType[number] == "Mastodon") { + post = MastodonLoadedFeed[CurrentThing + number]; + } else if (WebsiteAPIType[number] == "Bluesky") { + if (Mastodon == true) { + // *hardcoded bullshit* + number = number - 6; + } + post = BlueskyLoadedFeed[CurrentThing + number]; + } else { + return; + } + // Save some info + localStorage.setItem("post", JSON.stringify(post)); + document.location.href = "./HTML/expanded.html?website=" + website; + } +} // Call this to update the things :) async function PosterContainerUpdate(Direction) { let Lim = 6; let Website = localStorage.getItem(Variables.MastodonWebsite); - let Mastodon = true; - // Mastodon gaining of timeline. if (localStorage.getItem(Variables.MastodonWebsite) == null) { // The default website is Wetdry :3 @@ -135,6 +153,7 @@ async function PosterContainerUpdate(Direction) { if (localStorage.getItem(Variables.BlueskyPDS) == null) { console.log("No Bluesky instance. multiplying mastodon posts by 2..."); Lim = Lim * 2; + Bluesky = false; } else if (BlueskyLoadedFeed.length == 0) { BlueskyLoadedFeed = await BlueskyAPI.GetTimeline("").then((response) => response.feed); } @@ -145,9 +164,6 @@ async function PosterContainerUpdate(Direction) { CurrentThing = CurrentThing - Lim; } } - // Debugging - console.log(MastodonLoadedFeed); - console.log(BlueskyLoadedFeed); // The first one is for counting. // The countergroup increments to another timeline once posts hit the "limit". let counter = 0; @@ -155,33 +171,43 @@ async function PosterContainerUpdate(Direction) { if (Mastodon == false) { countergroup = countergroup + 1; } + if (Bluesky == false) { + countergroup = countergroup + 1; + } // This var is meant to stop "already seen" posts. let BlueskyPostsDup = []; + WebsiteAPIType = []; for (let i of ClickableContainers) { switch(countergroup) { // Mastodon case 0: + WebsiteAPIType.push("Mastodon"); if (MastodonLoadedFeed[CurrentThing + counter] == undefined) { let TempFeed = await MastodonAPI.GetTimeline(MastodonLoadedFeed[CurrentThing + counter - 1].id); MastodonLoadedFeed = MastodonLoadedFeed.concat(TempFeed); } + // Check for images. + if (MastodonLoadedFeed[CurrentThing + counter].media_attachments.length != 0) { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!
"; + } // Content warning. Don't show the content unless clicked!!! if (MastodonLoadedFeed[CurrentThing + counter].spoiler_text != "") { - i.getElementsByClassName("PostContent")[0].innerHTML = "WARNING: " + MastodonLoadedFeed[CurrentThing + counter].spoiler_text + ""; + i.getElementsByClassName("PostContent")[0].innerHTML += "WARNING: " + MastodonLoadedFeed[CurrentThing + counter].spoiler_text + ""; i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username; break; } // Check for a reblog. if (MastodonLoadedFeed[CurrentThing + counter].reblog != null) { - i.getElementsByClassName("PostContent")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].reblog.content; + i.getElementsByClassName("PostContent")[0].innerHTML += MastodonLoadedFeed[CurrentThing + counter].reblog.content; i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].reblog.account.username + " ( R: " + MastodonLoadedFeed[CurrentThing + counter].account.username + " )"; } else { - i.getElementsByClassName("PostContent")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].content; + i.getElementsByClassName("PostContent")[0].innerHTML += MastodonLoadedFeed[CurrentThing + counter].content; i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username; } break; // Bsky case 1: + WebsiteAPIType.push("Bluesky"); if (BlueskyLoadedFeed[CurrentThing + counter] == undefined) { let TempFeed = await BlueskyAPI.GetTimeline(BlueskyLoadedFeed[CurrentThing + counter - 1].post.indexedAt).then((response) => response.feed) BlueskyLoadedFeed = BlueskyLoadedFeed.concat(TempFeed); @@ -189,25 +215,32 @@ async function PosterContainerUpdate(Direction) { // check for "already seen" posts, then put it as a seen post. BlueskyLoadedFeed = CheckForDups(BlueskyLoadedFeed, BlueskyPostsDup, counter); BlueskyPostsDup.push(BlueskyLoadedFeed[counter].post.uri); + // Check for an image + if (BlueskyLoadedFeed[CurrentThing + counter].post.record.hasOwnProperty("embed") && BlueskyLoadedFeed[CurrentThing + counter].post.record.embed.$type == "app.bsky.embed.images") { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!
"; + } // Labels if (BlueskyLoadedFeed[CurrentThing + counter].post.labels.length != 0) { - i.getElementsByClassName("PostContent")[0].innerHTML = "LABELS APPLIED: "; + i.getElementsByClassName("PostContent")[0].innerHTML += "LABELS APPLIED: "; i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle; for (let lab of BlueskyLoadedFeed[CurrentThing + counter].post.labels) { - i.getElementsByClassName("PostContent")[0].innerHTML = i.getElementsByClassName("PostContent")[0].innerHTML + lab.val + " "; + i.getElementsByClassName("PostContent")[0].innerHTML += lab.val + " "; } - i.getElementsByClassName("PostContent")[0].innerHTML = i.getElementsByClassName("PostContent")[0].innerHTML + ""; + i.getElementsByClassName("PostContent")[0].innerHTML += ""; break; } // Check for a reblog if (BlueskyLoadedFeed[CurrentThing + counter].hasOwnProperty("reason") && BlueskyLoadedFeed[CurrentThing + counter].reason.$type == "app.bsky.feed.defs#reasonRepost") { - i.getElementsByClassName("PostContent")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.record.text; + i.getElementsByClassName("PostContent")[0].innerHTML += BlueskyLoadedFeed[CurrentThing + counter].post.record.text; i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle + " ( R: " + BlueskyLoadedFeed[CurrentThing + counter].reason.by.handle + " )"; } else { - i.getElementsByClassName("PostContent")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.record.text; + i.getElementsByClassName("PostContent")[0].innerHTML += BlueskyLoadedFeed[CurrentThing + counter].post.record.text; i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle; } - // Direction for where you go :3 + break; + case 2: + WebsiteAPIType.push("Nothing"); + console.log("The number you are trying to reach is unavailable. Try signing in dumbass."); break; } counter = counter + 1; diff --git a/JS/post.js b/JS/post.js index 3598f7c..0d9771f 100644 --- a/JS/post.js +++ b/JS/post.js @@ -8,21 +8,26 @@ let PostButton = document.getElementsByClassName("Button")[0]; let VisibilityDropdown = document.getElementsByClassName("PostVisibility")[0]; let InputArea = document.getElementsByClassName("Text")[0]; -// Extra Variables - - // Clicking the beeg POST button. PostButton.onclick = (event) => { Post(); } async function Post() { + let website; + if (document.location.href.split("website=").length > 1) { + website = document.location.href.split("website=")[1]; + } else { + website = "All"; + } + // Check to see if you are replying. let Text = InputArea.value; let Visible = VisibilityDropdown.value; // don't do anything if there is no value if (Text == "") { return; } + InputArea.value = ""; // Mastodon posting. if (localStorage.getItem(Variables.MastodonAccessToken) != null) { let TempVisible; @@ -40,7 +45,12 @@ async function Post() { TempVisible = "direct"; break; } - MastodonAPI.CreateStatus(Text, TempVisible); + if (website == "Mastodon") { + await MastodonAPI.CreateReplyStatus(Text, TempVisible, JSON.parse(localStorage.getItem("post")).id); + return; + } else if (website == "All") { + await MastodonAPI.CreateStatus(Text, TempVisible); + } } // Bluesky posting. if (localStorage.getItem(Variables.BlueskyAccessToken) != null) { @@ -59,10 +69,21 @@ async function Post() { TempVisible = []; break; } - let Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text); - let ThreadGate = await BlueskyAPI.SetThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible); + if (website == "Bluesky") { + if (JSON.parse(localStorage.getItem("post")).hasOwnProperty("reply")) { + let Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).reply.root); + await BlueskyAPI.SetThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible); + return; + } else { + let Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).post); + await BlueskyAPI.SetThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible); + return; + } + } else if (website == "All") { + let Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text); + await BlueskyAPI.SetThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible); + } } - InputArea.value = ""; } // Check if you can interact with the textbox diff --git a/index.html b/index.html index 23e16bb..8ca936d 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ The Fediverse +
-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+