103 lines
3.1 KiB
JavaScript
103 lines
3.1 KiB
JavaScript
import * as MastodonAPI from "./MastodonAPI.js";
|
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
|
import * as TumblrAPI from "./TumblrAPI.js";
|
|
import * as Cookie from "./Cookies.js";
|
|
|
|
// Settings buttons
|
|
let LocalButton = document.getElementsByClassName("Local")[0];
|
|
let RemoteButton = document.getElementsByClassName("Remote")[0];
|
|
|
|
let MastodonLoginButton = document.getElementsByClassName("Login Mastodon")[0];
|
|
let MastodonWebInput = document.getElementsByClassName("WebInput Mastodon")[0];
|
|
let MastodonLogoutButton = document.getElementsByClassName("Logout Mastodon")[0];
|
|
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
|
|
if (Cookie.IsCookieReal(Cookie.GetCookie("Local"))) {
|
|
Cookie.ExpireCookie("Local");
|
|
} else {
|
|
Cookie.InputCookie("Local", "true");
|
|
}
|
|
}
|
|
|
|
RemoteButton.onclick = (event) => {
|
|
// Toggle the cookie
|
|
if (Cookie.IsCookieReal(Cookie.GetCookie("Remote"))) {
|
|
Cookie.ExpireCookie("Remote");
|
|
} else {
|
|
Cookie.InputCookie("Remote", "true");
|
|
}
|
|
}
|
|
|
|
// Mastodon buttons
|
|
// Login
|
|
MastodonLoginButton.onclick = (event) => {
|
|
if (MastodonWebInput.value != "") {
|
|
let text = MastodonWebInput.value
|
|
MastodonAPI.HandleAuthentication(text);
|
|
}
|
|
}
|
|
|
|
// Logout
|
|
MastodonLogoutButton.onclick = (event) => {
|
|
Cookie.ExpireCookie(Cookie.MastodonClientIDName);
|
|
Cookie.ExpireCookie(Cookie.MastodonClientSecretName);
|
|
Cookie.ExpireCookie(Cookie.MastodonAccessTokenName);
|
|
Cookie.ExpireCookie(Cookie.MastodonTokenTypeName);
|
|
document.location.href = Origin;
|
|
}
|
|
|
|
// Bluesky Buttons
|
|
// Login
|
|
BlueskyLoginButton.onclick = (event) => {
|
|
if (BlueskyWebInput.value != "") {
|
|
BlueskyAPI.HandleAuthorization();
|
|
}
|
|
}
|
|
|
|
// Logout
|
|
BlueskyLogoutButton.onclick = (event) => {
|
|
Cookie.ExpireCookie(Cookie.BlueskyPKCEVeriferName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyPKCEChallengeName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyNonceName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyAccessTokenName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyRefreshTokenName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyPublicKeyName);
|
|
Cookie.ExpireCookie(Cookie.BlueskyPrivateKeyName);
|
|
document.location.href = Origin;
|
|
}
|
|
|
|
// if an access token is found, login.
|
|
async function CheckLogin() {
|
|
// Check for a mastodon token.
|
|
if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) {
|
|
// Swap the buttons
|
|
MastodonLoginButton.remove();
|
|
MastodonWebInput.remove();
|
|
MastodonLogoutButton.setAttribute("style", "");
|
|
} else {
|
|
// Auto log in
|
|
await MastodonAPI.GainToken(Cookie.MastodonWebsiteName);
|
|
}
|
|
// Check for a bluesky token.
|
|
if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) {
|
|
// Swap the buttons
|
|
BlueskyLoginButton.remove();
|
|
BlueskyWebInput.remove();
|
|
BlueskyLogoutButton.setAttribute("style", "");
|
|
} else {
|
|
// Auto log in
|
|
await BlueskyAPI.GainTokens();
|
|
}
|
|
}
|
|
|
|
// Runs on website start.
|
|
// Remove traces of "login".
|
|
CheckLogin();
|