Skip to content

Commit 5ab3cea

Browse files
authored
feat(アイドルマスターシャイニーカラーズ): implement iframe support to fix presence not updating (#10368)
1 parent a51e63d commit 5ab3cea

File tree

3 files changed

+103
-43
lines changed

3 files changed

+103
-43
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const iframe = new iFrame()
2+
let lastUrl = ''
3+
4+
iframe.on('UpdateData', async () => {
5+
const { pathname, hash } = document.location
6+
const currentUrl = pathname + hash
7+
8+
if (currentUrl !== lastUrl) {
9+
lastUrl = currentUrl
10+
await iframe.send({
11+
pathname,
12+
hash,
13+
})
14+
}
15+
})

websites/#/アイドルマスターシャイニーカラーズ/metadata.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
},
1616
"url": "shinycolors.enza.fun",
1717
"regExp": "^https?[:][/][/]shinycolors[.]enza[.]fun[/]",
18-
"version": "1.1.0",
19-
"logo": "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",
20-
"thumbnail": "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/thumbnail.png",
18+
"version": "2.0.0",
19+
"logo": "https://i.imgur.com/e6Zr6HQ.png",
20+
"thumbnail": "https://i.imgur.com/jH542Iz.png",
2121
"color": "#8adfff",
2222
"category": "games",
2323
"tags": [
2424
"game",
2525
"shinymas",
2626
"imas",
27-
"shinycolors"
28-
]
27+
"shinycolors",
28+
"idolmaster"
29+
],
30+
"iframe": true,
31+
"iFrameRegExp": "^https?[:][/][/]shinycolors[.]enza[.]fun[/]"
2932
}
Lines changed: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
const presence = new Presence({
22
clientId: '1103931016525127792',
33
})
4+
45
const browsingTimestamp = Math.floor(Date.now() / 1000)
56

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+
616
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+
825
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/',
1029
startTimestamp: browsingTimestamp,
11-
details: 'シャニマスをプレイ中',
30+
detailsUrl: `https://shinycolors.enza.fun${currentRoute}`,
1231
}
32+
1333
const pathMap: Record<string, PresenceData> = {
1434
'/home': { details: 'ホーム画面' },
1535
'/present': { details: 'プレゼント' },
1636
'/shop': { details: 'ショップ' },
37+
'/shop/premium': { details: 'プレミアムショップ' },
1738
'/shop/skin': { details: '衣装ショップ' },
1839
'/shop/game_event': { details: 'イベントショップ' },
1940
'/shop/money': { details: 'マニーショップ' },
@@ -57,49 +78,70 @@ presence.on('UpdateData', async () => {
5778
'/miniGamePortal': { details: 'ミニゲーム' },
5879
'/daifugo': { details: '大富豪をプレイ中' },
5980
'/characterProfile': { details: 'アイドルプロフィールを閲覧中' },
81+
'/photo': { details: 'フォトモード' },
82+
'/memoryBoost': { details: 'メモリーブースト' },
6083
}
61-
const pathDetails = pathMap[pathname]?.details
84+
85+
const pathDetails = pathMap[currentRoute]?.details
6286
if (typeof pathDetails !== 'undefined') {
6387
presenceData.details = pathDetails
6488
}
65-
else if (pathname.includes('/idolAlbum/')) {
89+
else if (currentRoute.includes('/idolAlbum/')) {
6690
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+
'郁田はるき',
95119
]
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) {
98126
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+
}
99140
}
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
103144
}
145+
104146
presence.setActivity(presenceData)
105147
})

0 commit comments

Comments
 (0)