Skip to content

Commit

Permalink
Add: ミニプレイヤーも一応対応
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Jun 18, 2024
1 parent 562aa8d commit 3f21e5f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
21 changes: 18 additions & 3 deletions src/inject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ if (location.pathname.includes("intro")) {
location.href = "https://kiite.jp/login?mode=cafe"
}

type GonGetter = () => Gon
type CafeMusicGetter = () => CafeMusic
type CafeUsersGetter = () => CafeUsers
type SnsUserGetter = () => SnsUser
type WindowFuncs = {
gon: GonGetter
cafeMusic: CafeMusicGetter
cafeUsers: CafeUsersGetter
snsUser: SnsUserGetter
getPlaylists: () => Promise<Playlist[]>
addPlaylistSong: (listId: string, songId: string) => Promise<boolean>
toggleCyalume: () => void
}
let gon: GonGetter | null = null
let cafeMusic: CafeMusicGetter | null = null
let cafeUsers: CafeUsersGetter | null = null
let getPlaylists: WindowFuncs["getPlaylists"] | null = null
Expand Down Expand Up @@ -68,6 +71,7 @@ const topMenus = [

contextBridge.exposeInMainWorld("preload", {
setFuncs: (funcs: WindowFuncs) => {
gon = funcs.gon
cafeMusic = funcs.cafeMusic
cafeUsers = funcs.cafeUsers
getPlaylists = funcs.getPlaylists
Expand Down Expand Up @@ -233,7 +237,16 @@ document.addEventListener("DOMContentLoaded", () => {
return this.pause()
},
}
player.load(callback)
;(async () => {
while (true) {
if (typeof window.YT === "undefined") {
await new Promise((resolve) => setTimeout(resolve, 100))
continue
}
player.load(callback)
break
}
})()
return this.play_history(musicInfo)
}
patchedPlay.isPatched = true
Expand All @@ -247,6 +260,7 @@ document.addEventListener("DOMContentLoaded", () => {
}, 100)

window.preload.setFuncs({
gon: () => window.gon,
cafeMusic: () => window.cafe_music,
cafeUsers: () => window.cafe_users,
snsUser: () => window.sns_user,
Expand Down Expand Up @@ -344,7 +358,7 @@ document.addEventListener("DOMContentLoaded", () => {

let lastMusicId: string | null = null
const sendUpdateIpc = (_mutations: MutationRecord[]) => {
if (!cafeUsers || !cafeUsers().me || !cafeMusic) {
if (!cafeUsers || !cafeUsers().me || !cafeMusic || !gon) {
return
}
if (lastMusicId !== cafeMusic().now_playing.video_id) {
Expand All @@ -361,7 +375,8 @@ document.addEventListener("DOMContentLoaded", () => {
endsAt: new Date(
new Date(nowPlaying.start_time).getTime() + nowPlaying.msec_duration
).getTime(),
id: nowPlaying.video_id,
id: gon().youtube_play ? nowPlaying.yt_video_id : nowPlaying.video_id,
source: gon().youtube_play ? "youtube" : "nicovideo",
progress:
parseFloat(
(
Expand Down
11 changes: 7 additions & 4 deletions src/inject/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ declare global {
CafePlayer: Class<CafePlayer>
CafeMusic: Class<CafeMusic>
d3: d3
gon: {
user: User
youtube_play: boolean
}
YT?: unknown
gon: Gon
}

interface Gon {
user: User
youtube_play: boolean
}

class CafeMusic {
Expand Down
14 changes: 12 additions & 2 deletions src/miniplayer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ const toggleFavorite = () => {
}
const openNico = () => {
window.open(`https://www.nicovideo.jp/watch/${info.value?.id}`)
if (!info.value) return
if (info.value.source === "nicovideo") {
window.open(`https://www.nicovideo.jp/watch/${info.value?.id}`)
}
if (info.value.source === "youtube") {
window.open(`https://youtube.com/watch?v=${info.value?.id}`)
}
}
const windowType = ref<"action" | "playlist" | "info">("info")
Expand All @@ -119,7 +125,11 @@ const tweet = () => {
if (!info.value) return
const text =
`♪ ${info.value.title} #${info.value.id} #Kiite\n` +
`Kiite Cafeできいてます https://cafe.kiite.jp https://nicovideo.jp/watch/${info.value.id}`
`Kiite Cafeできいてます https://cafe.kiite.jp ${
info.value.source === "nicovideo"
? `https://www.nicovideo.jp/watch/${info.value.id}`
: `https://youtube.com/watch?v=${info.value.id}`
}`
window.open(
`https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}`
)
Expand Down
1 change: 1 addition & 0 deletions type/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type NowPlayingInfo = {
thumbnail: string
publishedAt: string
id: string
source: "youtube" | "nicovideo"
progress: number
favorited: boolean
favoriteCount: number
Expand Down

0 comments on commit 3f21e5f

Please sign in to comment.