diff --git a/src/logic/data.ts b/src/logic/data.ts index 9b6f631ab..a0f3c34a7 100644 --- a/src/logic/data.ts +++ b/src/logic/data.ts @@ -43,3 +43,26 @@ export function parsePeopleJson(json: string): Person { export function url(base: string, params: { [id: string]: string }): string { return base + '?' + new URLSearchParams(params) } + +export interface Toast { + title: string, + text?: string, + img: string, + width?: number, + height?: number, + background?: string, + color?: string +} + +export type EggType = "open" | "tag" | "wait" | "keyword" +export type Tag = "p" | "summary" | "blockquote" | "div" | "pre" + +export interface EasterEgg { + type: EggType, + userid: string[], + id: string, + toast: Toast, + tag?: Tag, + wait?: number, + keyword?: string[] +} diff --git a/src/logic/easterEgg.ts b/src/logic/easterEgg.ts index 2614a4436..3bf092cc2 100644 --- a/src/logic/easterEgg.ts +++ b/src/logic/easterEgg.ts @@ -1,15 +1,16 @@ +import path from "path"; import Swal from "sweetalert2" -import {t} from "./config" -import {scheduledTask, toast} from "./helper" +import {dataHost, t} from "./config" +import {scheduledTask, toast, getResponseSync, checkSubset, randint} from "./helper" +import {EasterEgg} from "@/logic/data"; const registedEggItem = [ - 'hasFlowered', 'isSeenMeowBot233', 'BetelgeuseShown', 'ChongQingShown', 'Sea', 'detailsByYumao', 'funeralFlowers', 'preferredName', 'rhythmShown' + 'hasFlowered', 'preferredName' ] export function isEaster(): boolean { if (!localStorage.getItem('easterEggMode')) return false; - if (parseInt(localStorage.getItem('easterEggMode')) == 0) return false; - return true; + return parseInt(localStorage.getItem('easterEggMode')) != 0; } function allShown(): boolean { @@ -49,7 +50,7 @@ export function handleFlowerToast(name: string) { if (parseInt(localStorage.getItem('easterEggMode')) == 0) return; if (!localStorage.getItem("hasFlowered")) { localStorage.setItem("hasFlowered", "Meow") - toast("花与秋叶", `${name}收到你的小花啦~`, "lollipop_1f36d.png", null, 64, 64, null) + toast("花与秋叶", `${name}收到你的小花啦~`, "/img/lollipop_1f36d.png", null, 64, 64, null) } } @@ -78,10 +79,6 @@ export function handleEasterEgg(userid: string) { if (!localStorage.getItem('easterEggMode')) return; if (parseInt(localStorage.getItem('easterEggMode')) == 0) return; if (userid == "MeowBot233") { - if (!localStorage.getItem("isSeenMeowBot233")) { - localStorage.setItem("isSeenMeowBot233", "找到了喵~") - toast("找到了喵~", "诶? 找什么喵? ", "cat-face-emoji-2048x1828.png", null, 64, 57, null) - } if ((now.getDate() == 15) && (now.getMonth() == 3)) { if (!localStorage.getItem("birthdayMeowBot233")) localStorage.setItem("birthdayMeowBot233", (now.getFullYear() - 1).toString()) @@ -101,86 +98,72 @@ export function handleEasterEgg(userid: string) { } } } - if ((userid == "Anilovr") || (userid == "noname3031") || (userid == "dogesir_")) { - if (!localStorage.getItem("Betelgeuse")) - localStorage.setItem("Betelgeuse", `["${userid}"]`) - else { - const betelgeuse = JSON.parse(localStorage.getItem("Betelgeuse")) as string[] - if (!betelgeuse.includes(userid)) { - betelgeuse.push(userid) - localStorage.setItem("Betelgeuse", JSON.stringify(betelgeuse)) - } - if (betelgeuse.includes("Anilovr") && betelgeuse.includes("noname3031") && betelgeuse.includes("dogesir_") && (!localStorage.getItem("BetelgeuseShown"))) { - localStorage.setItem("BetelgeuseShown", "R.I.P.") - toast("参宿四 ~Betelgeuse~", "R.I.P. - Be resilient -", "betelgeuse.png", "url(/img/stardust.jpg)", 64, 64, '#f0f8ff') - } + const eggs = JSON.parse(getResponseSync(dataHost + '/eggs.json')) as EasterEgg[]; + const checkmate = (egg: EasterEgg) => { + if (!localStorage.getItem(egg.id)) localStorage.setItem(egg.id, `["${userid}"]`); + const opened = JSON.parse(localStorage.getItem(egg.id)) as string[]; + if (!opened.includes(userid)) { + opened.push(userid); + localStorage.setItem(egg.id, JSON.stringify(opened)); } - } - if ((userid == "xuewulihuameng") || (userid == "Futajuhuacha") || (userid == "Xu_Yushu") || (userid == "Dethelly")) { - if (!localStorage.getItem("ChongQing")) - localStorage.setItem("ChongQing", `["${userid}"]`) - else { - const ch = JSON.parse(localStorage.getItem("ChongQing")) as string[] - if (!ch.includes(userid)) { - ch.push(userid) - localStorage.setItem("ChongQing", JSON.stringify(ch)) - } - if (ch.includes("xuewulihuameng") && ch.includes("Futajuhuacha") && ch.includes("Xu_Yushu") && ch.includes("Dethelly") && (!localStorage.getItem("ChongQingShown"))) { - localStorage.setItem("ChongQingShown", "Fog") - toast("嘉陵雾稠", "雾终将散去, 而我们终将看到彩虹", "bridge.png", "url(/img/fog.jpg)", 64, 47, null) - } + if (checkSubset(opened, egg.userid) && checkSubset(egg.userid, opened)) { + localStorage.setItem(egg.id + '_SHOWN', randint(0, 2147483647).toString()); + toast(egg.toast.title, egg.toast.text, egg.toast.img, egg.toast.background, egg.toast.width, egg.toast.height, egg.toast.color); } + console.log(egg) } - if ((userid == "zhangyubaka") || (userid == "Uekawakuyuurei") || (userid == "MizuharaNagisa")) { - if (!localStorage.getItem("Boat")) - localStorage.setItem("Boat", `["${userid}"]`) - else { - const boat = JSON.parse(localStorage.getItem("Boat")) as string[] - if (!boat.includes(userid)) { - boat.push(userid) - localStorage.setItem("Boat", JSON.stringify(boat)) - } - if (boat.includes("zhangyubaka") && boat.includes("Uekawakuyuurei") && boat.includes("MizuharaNagisa") && (!localStorage.getItem("Sea"))) { - localStorage.setItem("Sea", "with you") - toast("海色", "拔锚起航, 跨越闪耀泪光的海岸", "ship.png", "#0b2058ff", 64, 64, '#f0f8feff') + for (const egg of eggs) { + registedEggItem.push(egg.id + '_SHOWN'); + switch (egg.type) { + case "open": { + if (egg.userid.includes(userid)) { + if (localStorage.getItem(egg.id + '_SHOWN')) break; + else checkmate(egg) + } + break; } - } - } - if ((userid == "zhangyubaka")) { - const summaries = document.getElementsByTagName("summary") - for (const v of summaries) { - console.log(v) - v.addEventListener('click', (e) => { - console.log("summary" + e) - if (!localStorage.getItem('detailsByYumao')) { - localStorage.setItem('detailsByYumao', 'forever.') - toast("往昔苦难", "因为妳而存在, 因为妳而不在, 要在啊......", "lifeline.png", "#EEEEEE88", 64, 64, null) + case "tag": { + if (egg.userid.includes(userid)) { + if (localStorage.getItem(egg.id + '_SHOWN')) break; + const elements = document.getElementsByTagName(egg.tag) + for (const v of elements) { + console.log(v) + v.addEventListener('click', (e) => { + console.log('tag' + e) + checkmate(egg) + }) + } } - }, false) - } - } - if ((userid == "mikaela_khara")) { - const summaries = document.getElementsByTagName("summary") - for (const v of summaries) { - console.log(v) - v.addEventListener('click', (e) => { - console.log("summary" + e) - if (!localStorage.getItem('mikaela_khara_ferris')) { - localStorage.setItem('mikaela_khara_ferris', '間關鶯語花底滑') - toast('永乐桥上的风景', '连绵不断的河流,像生命本身一样无法回头……', 'ferris-wheel.png', undefined, 64, 64, undefined); + break; + } + case "wait": { + if (egg.userid.includes(userid)) { + if (localStorage.getItem(egg.id + '_SHOWN')) break; + scheduledTask(30000, () => { + if ((window.location.pathname == `/profile/${userid}`) || window.location.pathname == `/profile/${userid}/`) { + checkmate(egg) + } + }) } - }) - } - } - if (userid == "shihai4h") { - scheduledTask(30000, () => { - if ((window.location.pathname == "/profile/shihai4h/") || (window.location.pathname == "/profile/shihai4h")) { - if (!localStorage.getItem("funeralFlowers")) { - localStorage.setItem("funeralFlowers", "shihai4h") - toast("葬花", "花谢花飞花满天, 红消香断有谁怜? ", "tumb.png", "url(/img/flowers.png)", 64, 64, null) + break; + } + case "keyword": { + if (egg.userid.includes(userid)) { + if (localStorage.getItem(egg.id + '_SHOWN')) break; + const ps = document.getElementsByTagName('p') + for (const v of ps) { + console.log(v) + for (const i of egg.keyword) { + if (v.innerHTML.includes(i) || v.innerText.includes(i)) { + v.addEventListener('click', () => { + checkmate(egg) + }) + } + } + } } } - }) + } } if (userid == "Xu_Yushu") { scheduledTask(20000, () => { @@ -203,28 +186,5 @@ export function handleEasterEgg(userid: string) { } }) } - if ((userid == "SevenBird") || (userid == "Considerate_cat") || (userid == "ttttsuuukikoo_") || (userid == "hakureico") || (userid == "xixi_yuexi") || (userid == "Jennife80677612")) { - const rhythmKeyword = ["音游", "音遊", "Arc", "舞萌", "maimaiDX", "OSU", "ptt", "Project Sekai"] - const ps = document.getElementsByTagName("p") - for (const v of ps) { - for (const i of rhythmKeyword) { - if (v.innerHTML.includes(i) || v.innerText.includes(i)) { - v.addEventListener('click', () => { - if (!localStorage.getItem("rhythm")) - localStorage.setItem("rhythm", `["${userid}"]`) - const rhythm = JSON.parse(localStorage.getItem("rhythm")) as string[] - if (!rhythm.includes(userid)) { - rhythm.push(userid) - localStorage.setItem("rhythm", JSON.stringify(rhythm)) - } - if (rhythm.includes("SevenBird") && rhythm.includes("Considerate_cat") && rhythm.includes("ttttsuuukikoo_") && rhythm.includes("hakureico") && rhythm.includes("xixi_yuexi") && rhythm.includes("Jennife80677612") && (!localStorage.getItem("rhythmShown"))) { - localStorage.setItem("rhythmShown", "AP end") - toast("希望有个 All Perfect 的结局", " ~ All that I'm left with is your reminiscences ~ ", "musical-score.png", null, 64, 64, null) - } - }, false) - } - } - } - } achieveAll() } \ No newline at end of file diff --git a/src/logic/helper.ts b/src/logic/helper.ts index 7a976ebc6..31795d4a6 100644 --- a/src/logic/helper.ts +++ b/src/logic/helper.ts @@ -151,7 +151,7 @@ export function toast(title: string, text: string, img: string, background: stri position: "top-end", title: title, text: text, - iconHtml: ``, + iconHtml: ``, iconColor: "#00000000", background: background, timer: 5000, @@ -229,4 +229,10 @@ export function gaussian_bm(min, max, skew) { num += min // offset to min } return num +} + +export function checkSubset(parentArray: any[], subsetArray: any[]): boolean { + return subsetArray.every((e) => { + return parentArray.includes(e) + }) } \ No newline at end of file diff --git a/src/logic/viaFetch.ts b/src/logic/viaFetch.ts index 80cac1def..06d241b46 100644 --- a/src/logic/viaFetch.ts +++ b/src/logic/viaFetch.ts @@ -1,9 +1,5 @@ -const easterImage = ['betelgeuse.png', 'bridge.png', 'cake.png', 'cat-face-emoji-2048x1828.png', 'clip.png', 'easterEgg.png', 'flowers.png', 'fog.png', 'lifeline.png', 'lollipop_1f36d.png', 'musical-score.png', 'ship.png', 'stardust.jpg', 'tumb.png'] - export function viaFetch(): void { - for (const v of easterImage) { - fetch(`/img/${v}`).then() - } + //Deleted } export function viaBalloon(): void {