84 lines
3.2 KiB
JavaScript
84 lines
3.2 KiB
JavaScript
// STRINGS TODO: make sure to seperate stuff that a user will want to input. Ex: MastodonWebsiteName, BlueskyPDS, etc.
|
|
// Mastodon
|
|
export const MastodonWebsiteName = "mastodon_website";
|
|
export const MastodonClientIDName = "mastodon_client_id";
|
|
export const MastodonClientSecretName = "mastodon_client_secret";
|
|
export const MastodonAccessTokenName = "mastodon_access_token";
|
|
export const MastodonTokenTypeName = "mastodon_token_type";
|
|
|
|
// Bluesky
|
|
export const BlueskyAppName = "https://bsky.app";
|
|
export const BlueskyPDSName = "https://bsky.social";
|
|
export const BlueskyPKCEVeriferName = "bluesky_pkce_verifier";
|
|
export const BlueskyPKCEChallengeName = "bluesky_pkce_challenge";
|
|
export const BlueskyPublicKeyName = "bluesky_public_key";
|
|
export const BlueskyPrivateKeyName = "bluesky_private_key";
|
|
export const BlueskyNonceName = "bluesky_nonce";
|
|
export const BlueskyAccessTokenName = "bluesky_access_token";
|
|
export const BlueskyRefreshTokenName = "bluesky_refresh_token";
|
|
|
|
// Tumblr
|
|
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);
|
|
export const MastodonTokenTypeCookie = GetCookie(MastodonTokenTypeName);
|
|
|
|
// Bluesky
|
|
export const BlueskyPKCEVeriferCookie = GetCookie(BlueskyPKCEVeriferName);
|
|
export const BlueskyPKCEChallengeCookie = GetCookie(BlueskyPKCEChallengeName);
|
|
export const BlueskyPublicKeyCookie = GetCookie(BlueskyPublicKeyName);
|
|
export const BlueskyPrivateKeyCookie = GetCookie(BlueskyPrivateKeyName);
|
|
export const BlueskyNonceCookie = GetCookie(BlueskyNonceName);
|
|
export const BlueskyAccessTokenCookie = GetCookie(BlueskyAccessTokenName);
|
|
export const BlueskyRefreshTokenCookie = GetCookie(BlueskyRefreshTokenName);
|
|
|
|
// Tumblr
|
|
// None lmao.
|
|
|
|
// FUNCTIONS
|
|
// Get the cookie from cookie storage.
|
|
export function GetCookie(CookieName = "") {
|
|
// Check if you put in nothing.
|
|
if (CookieName == 0) {
|
|
console.error("Where is the cookie name? Returning nothing...");
|
|
return "";
|
|
}
|
|
// Get the cookie.
|
|
let Cookie = document.cookie.split("; ").find((row) => row.startsWith(CookieName + "="))?.split("=");
|
|
// If the cookie doesn't exist...
|
|
if (Cookie == undefined || Cookie.length == 1) {
|
|
console.log("Cookie not found. Returning nothing...");
|
|
return "";
|
|
} else {
|
|
return Cookie[1];
|
|
}
|
|
}
|
|
|
|
// Check if a cookie is real (as in the value isn't nonexistant).
|
|
export function IsCookieReal(Cookie = "") {
|
|
if (Cookie.length == 0) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Remove the cookie.
|
|
export function ExpireCookie(CookieName = "") {
|
|
document.cookie = CookieName + "=nothing;samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
|
return;
|
|
}
|
|
|
|
// Add a new cookie (or change it's value).
|
|
export function InputCookie(CookieName = "", Value = "") {
|
|
if (Value == 0 || CookieName == 0) {
|
|
console.error("You forgot to put in a value. Stopping...");
|
|
return;
|
|
}
|
|
document.cookie = CookieName + "=" + Value + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"
|
|
return;
|
|
}
|