Optimizations & Fixing the settings
This commit is contained in:
parent
b566263e99
commit
62820d4ede
5 changed files with 47 additions and 95 deletions
|
@ -28,9 +28,8 @@ body {
|
||||||
border-width: 6px;
|
border-width: 6px;
|
||||||
border-color: #00FFFF;
|
border-color: #00FFFF;
|
||||||
|
|
||||||
padding: 8%;
|
padding: 8vh 6vw;
|
||||||
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
background: linear-gradient(#dcdcdc, #b4b4b4);
|
background: linear-gradient(#dcdcdc, #b4b4b4);
|
||||||
color: black;
|
color: black;
|
||||||
|
|
|
@ -15,31 +15,29 @@
|
||||||
<header>
|
<header>
|
||||||
<h1>Setting</h1>
|
<h1>Setting</h1>
|
||||||
</header>
|
</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">
|
<div class="Button">
|
||||||
<p class="Remote">Toggle Remote</p>
|
<p class="Remote">Toggle Remote</p>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Mastodon things. -->
|
||||||
<div class="Button">
|
<div class="Button">
|
||||||
<!-- Sorry people! -->
|
<input type="text" class="WebInput Mastodon" placeholder="Website (mastodon.social)"/>
|
||||||
<!-- Mastodon things. -->
|
<p class="Login Mastodon"><em>Login to Mastodon</em></p>
|
||||||
<div>
|
<p class="Logout Mastodon Hidden"><em>Logout of Mastodon</em></p>
|
||||||
<input type="text" class="WebInput Mastodon" placeholder="Website (mastodon.social)"/>
|
</div>
|
||||||
<p class="Login Mastodon"><em>Login to Mastodon</em></p>
|
<!-- Bluesky things. -->
|
||||||
<p class="Logout Mastodon Hidden"><em>Logout of Mastodon</em></p>
|
<div class="Button">
|
||||||
</div>
|
<input type="text" class="WebInput Bluesky" placeholder="Website (bsky.social)"/>
|
||||||
<!-- Bluesky things. -->
|
<p class="Login Bluesky"><em>Login to Bluesky</em></p>
|
||||||
<div>
|
<p class="Logout Bluesky Hidden"><em>Logout of Bluesky</em></p>
|
||||||
<input type="text" class="WebInput Bluesky" placeholder="Website (bsky.social)"/>
|
</div>
|
||||||
<p class="Login Bluesky"><em>Login to Bluesky</em></p>
|
<!-- Youtube things. -->
|
||||||
<p class="Logout Bluesky Hidden"><em>Logout of Bluesky</em></p>
|
<div class="Button">
|
||||||
</div>
|
<input type="text" class="WebInput Youtube" placeholder="Youtube API Key"/>
|
||||||
<!-- Youtube things. -->
|
<input type="text" class="WebInput Youtube" placeholder="Youtube Channel Handle"/>
|
||||||
<div>
|
<p class="Login Youtube"><em>Login to Youtube</em></p>
|
||||||
<input type="text" class="WebInput Youtube" placeholder="Youtube API Key"/>
|
<p class="Logout Youtube Hidden"><em>Logout of Youtube</em></p>
|
||||||
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
|
|
|
@ -115,7 +115,7 @@ export async function GetRecord(Repo, Collection, RKey) {
|
||||||
|
|
||||||
// Creators
|
// Creators
|
||||||
// This creates a post. Requires the DID of the account and the Text for the record.
|
// 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) {
|
if (Token == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -124,34 +124,18 @@ export async function CreatePost(DID, Text, ContentWarning = undefined) {
|
||||||
"text": Text,
|
"text": Text,
|
||||||
"createdAt": new Date(Date.now()).toISOString()
|
"createdAt": new Date(Date.now()).toISOString()
|
||||||
};
|
};
|
||||||
|
// Content warning stuff.
|
||||||
if (ContentWarning != undefined) {
|
if (ContentWarning != undefined) {
|
||||||
Record.labels = {
|
Record.labels = {
|
||||||
"$type": "com.atproto.label.defs#selfLabels",
|
"$type": "com.atproto.label.defs#selfLabels",
|
||||||
"values": [{
|
"values": [{
|
||||||
"val": ContentWarning
|
"val": ContentWarning
|
||||||
}]
|
}]
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
|
// ReplyID and RootID simultaniously.
|
||||||
if (body.hasOwnProperty("error") && body.error == "InvalidRequest") {
|
if (ReplyID != undefined && RootID != undefined) {
|
||||||
let matches = body.message.match(/(\d+)/);
|
Record.reply = {
|
||||||
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": {
|
|
||||||
"parent": {
|
"parent": {
|
||||||
"uri": ReplyID.uri,
|
"uri": ReplyID.uri,
|
||||||
"cid": ReplyID.cid
|
"cid": ReplyID.cid
|
||||||
|
@ -160,22 +144,18 @@ export async function CreateReplyPost(DID, Text, ReplyID, RootID, ContentWarning
|
||||||
"uri": RootID.uri,
|
"uri": RootID.uri,
|
||||||
"cid": RootID.cid
|
"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);
|
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
|
||||||
if (body.hasOwnProperty("error") && body.error == "InvalidRequest") {
|
if (body.hasOwnProperty("error") && body.error == "InvalidRequest") {
|
||||||
let matches = body.message.match(/(\d+)/);
|
let matches = body.message.match(/(\d+)/);
|
||||||
Record.text = Text.slice(0, matches[0] - 1);
|
Record.text = Text.slice(0, matches[0] - 1);
|
||||||
body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
|
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;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ export async function GetStatus(ID) {
|
||||||
|
|
||||||
// Creators
|
// Creators
|
||||||
// Make a status
|
// 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) {
|
if (Token == null || TokenType == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,13 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
|
||||||
Text = Text.replace(/(?:\r|\n|\r\n)/g, '<br>');
|
Text = Text.replace(/(?:\r|\n|\r\n)/g, '<br>');
|
||||||
// Get the correct fetch body.
|
// Get the correct fetch body.
|
||||||
let FetchThing = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses?status=" + encodeURIComponent(Text) + "&visibility=" + Visibility;
|
let FetchThing = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses?status=" + encodeURIComponent(Text) + "&visibility=" + Visibility;
|
||||||
|
// Content warning stuff.
|
||||||
if (SpoilerText != undefined) {
|
if (SpoilerText != undefined) {
|
||||||
FetchThing += "&spoiler_text=" + SpoilerText;
|
FetchThing += "&spoiler_text=" + SpoilerText;
|
||||||
}
|
}
|
||||||
|
if (ReplyID != undefined) {
|
||||||
|
FetchThing += "&in_reply_to_id=" + ReplyID;
|
||||||
|
}
|
||||||
// Send the request.
|
// Send the request.
|
||||||
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||||
let body = await request.then((response) => response.json());
|
let body = await request.then((response) => response.json());
|
||||||
|
@ -121,38 +125,9 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
|
||||||
// Send the request.
|
// Send the request.
|
||||||
request = fetch(enFetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
request = fetch(enFetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||||
body = await request.then((response) => response.json());
|
body = await request.then((response) => response.json());
|
||||||
await CreateReplyStatus(Text.slice(matches[0] - 1, SpoilerText, Text.length - 1), Visibility, body.id);
|
if (ReplyID != undefined) {
|
||||||
}
|
await CreateReplyStatus(Text.slice(matches[0] - 1, SpoilerText, Text.length), 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;
|
|
||||||
}
|
}
|
||||||
// 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;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
16
JS/post.js
16
JS/post.js
|
@ -50,9 +50,9 @@ async function Post() {
|
||||||
}
|
}
|
||||||
if (website == "Mastodon") {
|
if (website == "Mastodon") {
|
||||||
if (WarningInputArea.value == "") {
|
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 {
|
} 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 = "";
|
InputArea.value = "";
|
||||||
WarningInputArea.value = "";
|
WarningInputArea.value = "";
|
||||||
|
@ -60,9 +60,9 @@ async function Post() {
|
||||||
return;
|
return;
|
||||||
} else if (website == "All") {
|
} else if (website == "All") {
|
||||||
if (WarningInputArea.value == "") {
|
if (WarningInputArea.value == "") {
|
||||||
await MastodonAPI.CreateStatus(TempText, undefined, TempVisible);
|
await MastodonAPI.CreateStatus(TempText, TempVisible);
|
||||||
} else {
|
} else {
|
||||||
await MastodonAPI.CreateStatus(TempText, WarningInputArea.value, TempVisible);
|
await MastodonAPI.CreateStatus(TempText, TempVisible, WarningInputArea.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,16 +87,16 @@ async function Post() {
|
||||||
let Post;
|
let Post;
|
||||||
if (JSON.parse(localStorage.getItem("post")).hasOwnProperty("reply")) {
|
if (JSON.parse(localStorage.getItem("post")).hasOwnProperty("reply")) {
|
||||||
if (WarningInputArea.value == "") {
|
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 {
|
} 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);
|
await BlueskyAPI.CreateThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible);
|
||||||
} else {
|
} else {
|
||||||
if (WarningInputArea.value == "") {
|
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 {
|
} 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);
|
await BlueskyAPI.CreateThreadGate(localStorage.getItem(Variables.BlueskyDID), Post.uri, TempVisible);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue