mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-22 21:51:29 +00:00
winter banner
This commit is contained in:
3 files changed
+26
-9
No files matched your search
@@ -2,10 +2,13 @@ import "./banners/index.js";
|
||||
export interface banner {
|
||||
text: string | (() => string);
|
||||
url?: string;
|
||||
id?: string;
|
||||
priority: number;
|
||||
}
|
||||
let winner = null as null | banner;
|
||||
const seen = new Set(JSON.parse(localStorage.getItem("seenBanners") || "[]") as string[]);
|
||||
export function submitBanner(banner: banner) {
|
||||
if (banner.id && seen.has(banner.id)) return;
|
||||
if (!winner) winner = banner;
|
||||
if (winner.priority < banner.priority) winner = banner;
|
||||
}
|
||||
@@ -13,6 +16,10 @@ export function submitBanner(banner: banner) {
|
||||
let shown = false;
|
||||
export function showBanner() {
|
||||
if (shown || !winner) return;
|
||||
if (winner.id) {
|
||||
seen.add(winner.id);
|
||||
localStorage.setItem("seenBanners", JSON.stringify([...seen]));
|
||||
}
|
||||
shown = true;
|
||||
const noti = document.getElementById("noti")!;
|
||||
noti.textContent = "";
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import {I18n} from "../../i18n";
|
||||
//import {submitBanner} from "../bannerController";
|
||||
import {SnowFlake} from "../../snowflake";
|
||||
import {submitBanner} from "../bannerController";
|
||||
import {getBulkUsers, Specialuser} from "../utils";
|
||||
await I18n.done;
|
||||
/*
|
||||
submitBanner({
|
||||
text: I18n.donateMessage,
|
||||
url: "/donate",
|
||||
priority: 100,
|
||||
});
|
||||
*/
|
||||
const oldest = (Object.values(getBulkUsers().users) as Specialuser[]).reduce((prev, cur) => {
|
||||
console.log(cur.id);
|
||||
if (!cur.id) return prev;
|
||||
const t = SnowFlake.stringToUnixTime(cur.id);
|
||||
if (t < prev) return t;
|
||||
return prev;
|
||||
}, Infinity);
|
||||
//Only show in December and if the account is over a month old
|
||||
if (new Date().getMonth() === 11 && Date.now() - oldest > 1000 * 60 * 60 * 24 * 30)
|
||||
submitBanner({
|
||||
text: I18n.donateMessage,
|
||||
url: "/donate",
|
||||
priority: 100,
|
||||
id: "winter" + new Date().getFullYear(),
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"2faCode": "2FA code:",
|
||||
"donateMessage": "Donate to Fermi today!",
|
||||
"donateMessage": "Fermi survives on donations, please think about donating! Anything helps!",
|
||||
"404": {
|
||||
"404": "error:404 - Page Not Found",
|
||||
"app": "To the app",
|
||||
|
||||
Reference in new issue
Block a user