mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-08-29 01:18:44 +00:00
Merge branch 'pr-410'
This commit is contained in:
+6
-7
@@ -119,13 +119,12 @@ class I18n {
|
||||
static options() {
|
||||
return [...langmap.keys()].map((e) => e.replace(".json", ""));
|
||||
}
|
||||
static setLanguage(lang: string) {
|
||||
static async setLanguage(lang: string) {
|
||||
if (this.options().indexOf(lang) !== -1) {
|
||||
getPreferences().then(async (prefs) => {
|
||||
prefs.locale = lang;
|
||||
await I18n.create(lang);
|
||||
await setPreferences(prefs);
|
||||
});
|
||||
const prefs = getPreferences();
|
||||
prefs.locale = lang;
|
||||
await I18n.create(lang);
|
||||
await setPreferences(prefs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,7 +133,7 @@ let userLocale = navigator.language.slice(0, 2) || "en";
|
||||
if (I18n.options().indexOf(userLocale) === -1) {
|
||||
userLocale = "en";
|
||||
}
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const storage = prefs.locale;
|
||||
if (storage) {
|
||||
userLocale = storage;
|
||||
|
||||
@@ -337,7 +337,7 @@ class Localuser {
|
||||
}
|
||||
async queryBlog() {
|
||||
this.perminfo.localuser ??= {};
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const bstate = prefs.showBlogUpdates;
|
||||
if (bstate === undefined) {
|
||||
const pop = new Dialog("");
|
||||
@@ -461,7 +461,7 @@ class Localuser {
|
||||
}
|
||||
|
||||
this.pingEndpoint();
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const ml = document.getElementById("memberlisttoggle")!;
|
||||
if (prefs.checkMemberList) {
|
||||
ml.classList = "";
|
||||
@@ -2483,7 +2483,6 @@ class Localuser {
|
||||
async getPosts() {
|
||||
const text = await (await fetch("https://blog.fermi.chat/feed_rss_created.xml")).text();
|
||||
const xml = new DOMParser().parseFromString(text, "text/xml");
|
||||
console.log(xml, text);
|
||||
const posts = Array.from(xml.getElementsByTagName("channel")[0].getElementsByTagName("item"));
|
||||
return {
|
||||
items: posts.map((post) => {
|
||||
@@ -2531,7 +2530,7 @@ class Localuser {
|
||||
this.figureDefaultProvidor();
|
||||
}
|
||||
async figureDefaultProvidor() {
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
this.selectedGifProfidor =
|
||||
this.gifProvideors.find((_) => _.api_name == prefs.gifProvidor) || this.gifProvideors[0];
|
||||
}
|
||||
@@ -2583,7 +2582,7 @@ class Localuser {
|
||||
});
|
||||
}
|
||||
async showusersettings() {
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const localSettings = getLocalSettings();
|
||||
const settings = new Settings(I18n.localuser.settings());
|
||||
{
|
||||
@@ -3014,7 +3013,7 @@ class Localuser {
|
||||
}
|
||||
|
||||
{
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const tas = settings.addButton(I18n.localuser.themesAndSounds(), {contained: true});
|
||||
{
|
||||
const themes = ["Dark", "WHITE", "Light", "Dark-Accent"];
|
||||
@@ -3145,6 +3144,18 @@ class Localuser {
|
||||
{defaultIndex: ind === -1 ? 0 : ind},
|
||||
);
|
||||
}
|
||||
{
|
||||
tas.addCheckboxInput(
|
||||
"Show today at:",
|
||||
(b) => {
|
||||
prefs.showToday = b;
|
||||
setPreferences(prefs);
|
||||
},
|
||||
{
|
||||
initState: prefs.showToday,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
{
|
||||
const blog = settings.addButton(I18n.blog.blog(), {contained: true});
|
||||
@@ -5236,7 +5247,7 @@ class Localuser {
|
||||
readonly presences: Map<string, presencejson> = new Map();
|
||||
static font?: FontFace;
|
||||
static async loadFont() {
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
const fontName = prefs.emojiFont;
|
||||
|
||||
if (this.font) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import {Components} from "./interactions/compontents.js";
|
||||
import {ImagesDisplay} from "./disimg";
|
||||
import {ReportMenu} from "./reporting/report.js";
|
||||
import {getDeveloperSettings} from "./utils/storage/devSettings.js";
|
||||
import {getPreferences} from "./utils/storage/userPreferences.js";
|
||||
class Message extends SnowFlake {
|
||||
static contextmenu = new Contextmenu<Message, void>("message menu");
|
||||
stickers!: Sticker[];
|
||||
@@ -1773,13 +1774,14 @@ let now: string;
|
||||
let yesterdayStr: string;
|
||||
|
||||
function formatTime(date: Date) {
|
||||
const conf = getPreferences();
|
||||
updateTimes();
|
||||
const datestring = date.toLocaleDateString();
|
||||
const formatTime = (date: Date) =>
|
||||
date.toLocaleTimeString([], {hour: "2-digit", minute: "2-digit"});
|
||||
|
||||
if (datestring === now) {
|
||||
return I18n.todayAt(formatTime(date));
|
||||
return conf.showToday ? I18n.todayAt(formatTime(date)) : formatTime(date);
|
||||
} else if (datestring === yesterdayStr) {
|
||||
return I18n.yesterdayAt(formatTime(date));
|
||||
} else {
|
||||
|
||||
@@ -36,13 +36,14 @@ export class UserPreferences {
|
||||
emojiFont?: string;
|
||||
checkMemberList = false;
|
||||
gifProvidor?: string;
|
||||
showToday = true;
|
||||
|
||||
constructor(init?: Partial<UserPreferences>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPreferences(): Promise<UserPreferences> {
|
||||
export function getPreferences(): UserPreferences {
|
||||
return new UserPreferences(JSON.parse(localStorage.getItem("userPreferences") || "{}"));
|
||||
}
|
||||
|
||||
|
||||
+15
-17
@@ -32,7 +32,7 @@ let instances:
|
||||
| null = null;
|
||||
await setTheme();
|
||||
export async function setTheme(theme?: string) {
|
||||
const prefs = await getPreferences();
|
||||
const prefs = getPreferences();
|
||||
document.body.className = (theme || prefs.theme) + "-theme";
|
||||
console.log(theme);
|
||||
}
|
||||
@@ -87,9 +87,9 @@ export function setDefaults() {
|
||||
userinfos.accent_color = "#3096f7";
|
||||
}
|
||||
|
||||
getPreferences().then((perfs) =>
|
||||
document.documentElement.style.setProperty("--accent-color", perfs.accentColor),
|
||||
);
|
||||
const perfs = getPreferences();
|
||||
document.documentElement.style.setProperty("--accent-color", perfs.accentColor);
|
||||
|
||||
if (userinfos.preferences === undefined) {
|
||||
userinfos.preferences = {
|
||||
theme: "Dark",
|
||||
@@ -749,14 +749,12 @@ export function createImg(
|
||||
elm: HTMLElement | void,
|
||||
type: "gif" | "icon" = "gif",
|
||||
): safeImg {
|
||||
const aniOpt = getPreferences().then((prefs) => {
|
||||
return (
|
||||
(type === "gif" ? prefs.animateGifs : prefs.animateIcons) ||
|
||||
("hover" as "hover") ||
|
||||
"always" ||
|
||||
"never"
|
||||
);
|
||||
});
|
||||
const prefs = getPreferences();
|
||||
const aniOpt =
|
||||
(type === "gif" ? prefs.animateGifs : prefs.animateIcons) ||
|
||||
("hover" as "hover") ||
|
||||
"always" ||
|
||||
"never";
|
||||
const img = document.createElement("img");
|
||||
img.loading = "lazy";
|
||||
img.decoding = "async";
|
||||
@@ -769,11 +767,11 @@ export function createImg(
|
||||
if (animated) {
|
||||
img.crossOrigin = "anonymous";
|
||||
}
|
||||
img.src = (await aniOpt) !== "always" ? staticsrc || src || "" : src || "";
|
||||
img.src = aniOpt !== "always" ? staticsrc || src || "" : src || "";
|
||||
});
|
||||
}
|
||||
img.onload = async () => {
|
||||
if ((await aniOpt) === "always") return;
|
||||
if (aniOpt === "always") return;
|
||||
if (!src) return;
|
||||
if ((await isAnimated(src)) && !staticsrc) {
|
||||
let s = staticImgMap.get(src);
|
||||
@@ -797,13 +795,13 @@ export function createImg(
|
||||
}
|
||||
};
|
||||
elm.addEventListener("mouseover", async () => {
|
||||
if ((await aniOpt) === "never") return;
|
||||
if (aniOpt === "never") return;
|
||||
if (img.src !== src && src) {
|
||||
img.src = src;
|
||||
}
|
||||
});
|
||||
elm.addEventListener("mouseleave", async () => {
|
||||
if (staticsrc && (await aniOpt) !== "always") {
|
||||
if (staticsrc && aniOpt !== "always") {
|
||||
img.src = staticsrc;
|
||||
}
|
||||
});
|
||||
@@ -817,7 +815,7 @@ export function createImg(
|
||||
if (animated) {
|
||||
img.crossOrigin = "anonymous";
|
||||
}
|
||||
img.src = (await aniOpt) !== "always" ? staticsrc || src || "" : src || "";
|
||||
img.src = aniOpt !== "always" ? staticsrc || src || "" : src || "";
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user