Optimizations & Fixing the settings

This commit is contained in:
CatAClock 2025-05-30 15:28:04 -07:00
parent b566263e99
commit 62820d4ede
5 changed files with 47 additions and 95 deletions

View file

@ -28,9 +28,8 @@ body {
border-width: 6px;
border-color: #00FFFF;
padding: 8%;
padding: 8vh 6vw;
display: flex;
justify-content: center;
background: linear-gradient(#dcdcdc, #b4b4b4);
color: black;

View file

@ -15,31 +15,29 @@
<header>
<h1>Setting</h1>
</header>
<div style="display: flex; justify-content: center; height: 75vh;">
<div style="display: flex; flex-wrap: wrap; justify-content: center; height: 75vh;">
<!-- Toggling things. -->
<div class="Button">
<p class="Remote">Toggle Remote</p>
</div>
<!-- Mastodon things. -->
<div class="Button">
<!-- Sorry people! -->
<!-- Mastodon things. -->
<div>
<input type="text" class="WebInput Mastodon" placeholder="Website (mastodon.social)"/>
<p class="Login Mastodon"><em>Login to Mastodon</em></p>
<p class="Logout Mastodon Hidden"><em>Logout of Mastodon</em></p>
</div>
<!-- Bluesky things. -->
<div>
<input type="text" class="WebInput Bluesky" placeholder="Website (bsky.social)"/>
<p class="Login Bluesky"><em>Login to Bluesky</em></p>
<p class="Logout Bluesky Hidden"><em>Logout of Bluesky</em></p>
</div>
<!-- Youtube things. -->
<div>
<input type="text" class="WebInput Youtube" placeholder="Youtube API Key"/>
<input type="text" class="WebInput Youtube" placeholder="Youtube Channel Handle"/>
<p class="Login Youtube"><em>Login to Youtube</em></p>
<p class="Logout Youtube Hidden"><em>Logout of Youtube</em></p>
</div>
<input type="text" class="WebInput Mastodon" placeholder="Website (mastodon.social)"/>
<p class="Login Mastodon"><em>Login to Mastodon</em></p>
<p class="Logout Mastodon Hidden"><em>Logout of Mastodon</em></p>
</div>
<!-- Bluesky things. -->
<div class="Button">
<input type="text" class="WebInput Bluesky" placeholder="Website (bsky.social)"/>
<p class="Login Bluesky"><em>Login to Bluesky</em></p>
<p class="Logout Bluesky Hidden"><em>Logout of Bluesky</em></p>
</div>
<!-- Youtube things. -->
<div class="Button">
<input type="text" class="WebInput Youtube" placeholder="Youtube API Key"/>
<input type="text" class="WebInput Youtube" placeholder="Youtube Channel Handle"/>
<p class="Login Youtube"><em>Login to Youtube</em></p>
<p class="Logout Youtube Hidden"><em>Logout of Youtube</em></p>
</div>
</div>
<footer>

View file

@ -115,7 +115,7 @@ export async function GetRecord(Repo, Collection, RKey) {
// Creators
// This creates a post. Requires the DID of the account and the Text for the record.
export async function CreatePost(DID, Text, ContentWarning = undefined) {
export async function CreatePost(DID, Text, ContentWarning = undefined, ReplyID = undefined, RootID = undefined) {
if (Token == null) {
return "";
}
@ -124,34 +124,18 @@ export async function CreatePost(DID, Text, ContentWarning = undefined) {
"text": Text,
"createdAt": new Date(Date.now()).toISOString()
};
// Content warning stuff.
if (ContentWarning != undefined) {
Record.labels = {
"$type": "com.atproto.label.defs#selfLabels",
"values": [{
"val": ContentWarning
}]
}
};
}
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
if (body.hasOwnProperty("error") && body.error == "InvalidRequest") {
let matches = body.message.match(/(\d+)/);
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;
}
// Creates a reply post. The RootID is always the first post, the ReplyID is the post you are replying to.
export async function CreateReplyPost(DID, Text, ReplyID, RootID, ContentWarning = undefined) {
if (Token == null) {
return "";
}
let Record = {
"$type": "app.bsky.feed.post",
"text": Text,
"createdAt": new Date(Date.now()).toISOString(),
"reply": {
// ReplyID and RootID simultaniously.
if (ReplyID != undefined && RootID != undefined) {
Record.reply = {
"parent": {
"uri": ReplyID.uri,
"cid": ReplyID.cid
@ -160,22 +144,18 @@ export async function CreateReplyPost(DID, Text, ReplyID, RootID, ContentWarning
"uri": RootID.uri,
"cid": RootID.cid
}
}
};
if (ContentWarning != undefined) {
Record.labels = {
"$type": "com.atproto.label.defs#selfLabels",
"values": [{
"val": ContentWarning
}]
}
};
}
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
if (body.hasOwnProperty("error") && body.error == "InvalidRequest") {
let matches = body.message.match(/(\d+)/);
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);
if (ReplyID != undefined && RootID != undefined) {
await CreatePost(DID, Text.slice(matches[0] - 1, Text.length), ContentWarning, body, body);
} else {
await CreatePost(DID, Text.slice(matches[0] - 1, Text.length), ContentWarning, body, RootID);
}
}
return body;
}

View file

@ -95,7 +95,7 @@ export async function GetStatus(ID) {
// Creators
// Make a status
export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "public") {
export async function CreateStatus(Text, Visibility = "public", SpoilerText = undefined, ReplyID = undefined) {
if (Token == null || TokenType == null) {
return "";
}
@ -103,9 +103,13 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
Text = Text.replace(/(?:\r|\n|\r\n)/g, '<br>');
// Get the correct fetch body.
let FetchThing = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses?status=" + encodeURIComponent(Text) + "&visibility=" + Visibility;
// Content warning stuff.
if (SpoilerText != undefined) {
FetchThing += "&spoiler_text=" + SpoilerText;
}
if (ReplyID != undefined) {
FetchThing += "&in_reply_to_id=" + ReplyID;
}
// Send the request.
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
let body = await request.then((response) => response.json());
@ -121,38 +125,9 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
// Send the request.
request = fetch(enFetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
body = await request.then((response) => response.json());
await CreateReplyStatus(Text.slice(matches[0] - 1, SpoilerText, Text.length - 1), Visibility, body.id);
}
return body;
}
export async function CreateReplyStatus(Text, SpoilerText = undefined, Visibility = "public", ReplyID) {
if (Token == null || TokenType == null) {
return "";
}
// Stolen from StackOverflow
Text = Text.replace(/(?:\r|\n|\r\n)/g, '<br>');
// Get the correct fetch body.
let FetchThing = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses?status=" + encodeURIComponent(Text) + "&visibility=" + Visibility + "&in_reply_to_id=" + ReplyID;
if (SpoilerText != undefined) {
FetchThing += "&spoiler_text=" + SpoilerText;
}
// Send the request.
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
let body = await request.then((response) => response.json());
let status = await request.then((response) => response.status);
// This is in case you went over the characters.
if (status == 422) {
let matches = body.error.match(/(\d+)/);
// Get the correct fetch body.
FetchThing = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses?status=" + encodeURIComponent(Text.slice(0, matches[0] - 1)) + "&visibility=" + Visibility + "&in_reply_to_id=" + ReplyID;
if (SpoilerText != undefined) {
FetchThing += "&spoiler_text=" + SpoilerText;
if (ReplyID != undefined) {
await CreateReplyStatus(Text.slice(matches[0] - 1, SpoilerText, Text.length), Visibility, body.id);
}
// Send the request.
request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
body = await request.then((response) => response.json());
await CreateReplyStatus(Text.slice(matches[0] - 1, Text.length - 1), SpoilerText, Visibility, body.id);
}
return body;
}

View file

@ -50,9 +50,9 @@ async function Post() {
}
if (website == "Mastodon") {
if (WarningInputArea.value == "") {
await MastodonAPI.CreateReplyStatus(TempText, undefined, TempVisible, JSON.parse(localStorage.getItem("post")).id);
await MastodonAPI.CreateStatus(TempText, TempVisible, undefined, JSON.parse(localStorage.getItem("post")).id);
} else {
await MastodonAPI.CreateReplyStatus(TempText, WarningInputArea.value, TempVisible, JSON.parse(localStorage.getItem("post")).id);
await MastodonAPI.CreateStatus(TempText, TempVisible, WarningInputArea.value, JSON.parse(localStorage.getItem("post")).id);
}
InputArea.value = "";
WarningInputArea.value = "";
@ -60,9 +60,9 @@ async function Post() {
return;
} else if (website == "All") {
if (WarningInputArea.value == "") {
await MastodonAPI.CreateStatus(TempText, undefined, TempVisible);
await MastodonAPI.CreateStatus(TempText, TempVisible);
} else {
await MastodonAPI.CreateStatus(TempText, WarningInputArea.value, TempVisible);
await MastodonAPI.CreateStatus(TempText, TempVisible, WarningInputArea.value);
}
}
}
@ -87,16 +87,16 @@ async function Post() {
let Post;
if (JSON.parse(localStorage.getItem("post")).hasOwnProperty("reply")) {
if (WarningInputArea.value == "") {
Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).reply.root);
Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text, undefined, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).reply.root);
} else {
Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).reply.root, WarningInputArea.value);
Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text, WarningInputArea.value, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).reply.root);
}
await BlueskyAPI.CreateThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible);
} else {
if (WarningInputArea.value == "") {
Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).post);
Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text, undefined, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).post);
} else {
Post = await BlueskyAPI.CreateReplyPost(localStorage.getItem(Variables.BlueskyDID), Text, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).post, WarningInputArea.value);
Post = await BlueskyAPI.CreatePost(localStorage.getItem(Variables.BlueskyDID), Text, WarningInputArea.value, JSON.parse(localStorage.getItem("post")).post, JSON.parse(localStorage.getItem("post")).post);
}
await BlueskyAPI.CreateThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible);
}