|
1 | 1 | const presence = new Presence({ |
2 | 2 | clientId: '1103931016525127792', |
3 | 3 | }) |
| 4 | + |
4 | 5 | const browsingTimestamp = Math.floor(Date.now() / 1000) |
5 | 6 |
|
| 7 | +let iframeState: { pathname: string, hash: string } | null = null |
| 8 | +let lastDetails = '' |
| 9 | + |
| 10 | +presence.on('iFrameData', (data: any) => { |
| 11 | + if (data && data.hash && data.hash.startsWith('#/')) { |
| 12 | + iframeState = data |
| 13 | + } |
| 14 | +}) |
| 15 | + |
6 | 16 | presence.on('UpdateData', async () => { |
7 | | - const { pathname } = document.location |
| 17 | + const { pathname: parentPath, hash: parentHash } = document.location |
| 18 | + |
| 19 | + const currentPath = iframeState?.pathname ?? parentPath |
| 20 | + const currentHash = iframeState?.hash ?? parentHash |
| 21 | + |
| 22 | + const cleanHash = currentHash ? currentHash.split('?')[0] : '' |
| 23 | + const currentRoute = (cleanHash && cleanHash.length > 1) ? cleanHash.substring(1) : currentPath |
| 24 | + |
8 | 25 | const presenceData: PresenceData = { |
9 | | - largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/%23/%E3%82%A2%E3%82%A4%E3%83%89%E3%83%AB%E3%83%9E%E3%82%B9%E3%82%BF%E3%83%BC%E3%82%B7%E3%83%A3%E3%82%A4%E3%83%8B%E3%83%BC%E3%82%AB%E3%83%A9%E3%83%BC%E3%82%BA/assets/logo.png', |
| 26 | + name: 'シャニマス', |
| 27 | + largeImageKey: 'https://i.imgur.com/e6Zr6HQ.png', |
| 28 | + largeImageUrl: 'https://shinycolors.enza.fun/', |
10 | 29 | startTimestamp: browsingTimestamp, |
11 | | - details: 'シャニマスをプレイ中', |
| 30 | + detailsUrl: `https://shinycolors.enza.fun${currentRoute}`, |
12 | 31 | } |
| 32 | + |
13 | 33 | const pathMap: Record<string, PresenceData> = { |
14 | 34 | '/home': { details: 'ホーム画面' }, |
15 | 35 | '/present': { details: 'プレゼント' }, |
16 | 36 | '/shop': { details: 'ショップ' }, |
| 37 | + '/shop/premium': { details: 'プレミアムショップ' }, |
17 | 38 | '/shop/skin': { details: '衣装ショップ' }, |
18 | 39 | '/shop/game_event': { details: 'イベントショップ' }, |
19 | 40 | '/shop/money': { details: 'マニーショップ' }, |
@@ -57,49 +78,70 @@ presence.on('UpdateData', async () => { |
57 | 78 | '/miniGamePortal': { details: 'ミニゲーム' }, |
58 | 79 | '/daifugo': { details: '大富豪をプレイ中' }, |
59 | 80 | '/characterProfile': { details: 'アイドルプロフィールを閲覧中' }, |
| 81 | + '/photo': { details: 'フォトモード' }, |
| 82 | + '/memoryBoost': { details: 'メモリーブースト' }, |
60 | 83 | } |
61 | | - const pathDetails = pathMap[pathname]?.details |
| 84 | + |
| 85 | + const pathDetails = pathMap[currentRoute]?.details |
62 | 86 | if (typeof pathDetails !== 'undefined') { |
63 | 87 | presenceData.details = pathDetails |
64 | 88 | } |
65 | | - else if (pathname.includes('/idolAlbum/')) { |
| 89 | + else if (currentRoute.includes('/idolAlbum/')) { |
66 | 90 | const idolNames: string[] = [ |
67 | | - '真乃', |
68 | | - '灯織', |
69 | | - 'めぐる', |
70 | | - '恋鐘', |
71 | | - '摩美々', |
72 | | - '咲耶', |
73 | | - '結華', |
74 | | - '霧子', |
75 | | - '果穂', |
76 | | - '智代子', |
77 | | - '樹里', |
78 | | - '凛世', |
79 | | - '夏葉', |
80 | | - '甘奈', |
81 | | - '甜花', |
82 | | - '千雪', |
83 | | - 'あさひ', |
84 | | - '冬優子', |
85 | | - '愛依', |
86 | | - '透', |
87 | | - '円香', |
88 | | - '小糸', |
89 | | - '雛菜', |
90 | | - 'にちか', |
91 | | - '美琴', |
92 | | - 'ルカ', |
93 | | - '羽那', |
94 | | - 'はるき', |
| 91 | + '櫻木真乃', |
| 92 | + '風野灯織', |
| 93 | + '八宮めぐる', |
| 94 | + '月岡恋鐘', |
| 95 | + '田中摩美々', |
| 96 | + '白瀬咲耶', |
| 97 | + '三峰結華', |
| 98 | + '幽谷霧子', |
| 99 | + '小宮果穂', |
| 100 | + '園田智代子', |
| 101 | + '西城樹里', |
| 102 | + '杜野凛世', |
| 103 | + '有栖川夏葉', |
| 104 | + '大崎甘奈', |
| 105 | + '大崎甜花', |
| 106 | + '桑山千雪', |
| 107 | + '芹沢あさひ', |
| 108 | + '黛冬優子', |
| 109 | + '和泉愛依', |
| 110 | + '浅倉透', |
| 111 | + '樋口円香', |
| 112 | + '福丸小糸', |
| 113 | + '市川雛菜', |
| 114 | + '七草にちか', |
| 115 | + '緋田美琴', |
| 116 | + '斑鳩ルカ', |
| 117 | + '鈴木羽那', |
| 118 | + '郁田はるき', |
95 | 119 | ] |
96 | | - const albumIndex = Number(pathname.split('/')[2]) - 1 |
97 | | - if (albumIndex >= 0 && albumIndex < idolNames.length) |
| 120 | + |
| 121 | + const parts = currentRoute.split('/') |
| 122 | + const idStr = parts[parts.length - 1] |
| 123 | + const albumIndex = Number(idStr) - 1 |
| 124 | + |
| 125 | + if (albumIndex >= 0 && albumIndex < idolNames.length) { |
98 | 126 | presenceData.details = `${idolNames[albumIndex]}のアルバムを閲覧中` |
| 127 | + } |
| 128 | + |
| 129 | + const oshiId = Number(idStr) |
| 130 | + const oshiMap: Record<number, string> = { |
| 131 | + 91: '七草はづき', |
| 132 | + 801: 'ルビー', |
| 133 | + 802: '有馬かな', |
| 134 | + 803: 'MEMちょ', |
| 135 | + 804: '黒川あかね', |
| 136 | + } |
| 137 | + if (oshiMap[oshiId]) { |
| 138 | + presenceData.details = `${oshiMap[oshiId]}のアルバムを閲覧中` |
| 139 | + } |
99 | 140 | } |
100 | | - for (const [index, idolName] of ['ルビー', '有馬かな', 'MEMちょ'].entries()) { |
101 | | - if (pathname === `/idolAlbum/${801 + index}`) |
102 | | - presenceData.details = `${idolName}のアルバムを閲覧中` |
| 141 | + |
| 142 | + if (presenceData.details !== lastDetails) { |
| 143 | + lastDetails = presenceData.details as string |
103 | 144 | } |
| 145 | + |
104 | 146 | presence.setActivity(presenceData) |
105 | 147 | }) |
0 commit comments