|
| 1 | +import { ActivityType, Assets } from 'premid' |
| 2 | + |
| 3 | +const presence = new Presence({ |
| 4 | + clientId: '1460189621353709805', |
| 5 | +}) |
| 6 | + |
| 7 | +presence.on('UpdateData', async () => { |
| 8 | + const presenceData: PresenceData = { |
| 9 | + type: ActivityType.Watching, |
| 10 | + largeImageKey: 'https://raw.githubusercontent.com/sirschubert/assets/refs/heads/main/assets/sudomemo-logo.png', |
| 11 | + } |
| 12 | + |
| 13 | + const { pathname } = document.location |
| 14 | + |
| 15 | + if (pathname === '/' || pathname.includes('/browse')) { |
| 16 | + presenceData.state = 'Browsing homepage' |
| 17 | + presenceData.smallImageKey = Assets.Viewing |
| 18 | + presenceData.smallImageText = 'Browsing' |
| 19 | + } |
| 20 | + |
| 21 | + else if (pathname.includes('/categories')) { |
| 22 | + const categoryName = document.querySelector('.category-header > h1')?.textContent |
| 23 | + |
| 24 | + if (categoryName) { |
| 25 | + presenceData.details = 'Browsing channels in category:' |
| 26 | + presenceData.state = `"${categoryName}"` |
| 27 | + } |
| 28 | + else { |
| 29 | + presenceData.state = 'Browsing channels by categories' |
| 30 | + } |
| 31 | + presenceData.smallImageKey = Assets.Viewing |
| 32 | + presenceData.smallImageText = 'Browsing' |
| 33 | + } |
| 34 | + |
| 35 | + else if (pathname.includes('/channel')) { |
| 36 | + const channelName = document.querySelector('.card-header.theme-panel-title > span')?.textContent |
| 37 | + |
| 38 | + presenceData.details = 'Browsing flipnotes in channel:' |
| 39 | + presenceData.state = `${channelName}` |
| 40 | + presenceData.smallImageKey = Assets.Viewing |
| 41 | + presenceData.smallImageText = 'Browsing' |
| 42 | + } |
| 43 | + |
| 44 | + else if (pathname.includes('/shop')) { |
| 45 | + presenceData.state = 'Shopping...' |
| 46 | + } |
| 47 | + |
| 48 | + else if (pathname.includes('/news')) { |
| 49 | + presenceData.state = 'Reading the news' |
| 50 | + presenceData.smallImageKey = Assets.Reading |
| 51 | + presenceData.smallImageText = 'Reading' |
| 52 | + } |
| 53 | + |
| 54 | + else if (pathname.includes('/search')) { |
| 55 | + const params = new URLSearchParams(window.location.search) |
| 56 | + const searchquery = params.get('q') |
| 57 | + |
| 58 | + if (searchquery) { |
| 59 | + presenceData.state = `Searching for "${decodeURIComponent(searchquery)}"` |
| 60 | + } |
| 61 | + else { |
| 62 | + presenceData.state = 'Searching...' |
| 63 | + } |
| 64 | + |
| 65 | + presenceData.smallImageKey = Assets.Search |
| 66 | + presenceData.smallImageText = 'Searching' |
| 67 | + } |
| 68 | + |
| 69 | + else if (pathname.includes('/watch')) { |
| 70 | + const flipName = document.querySelector('.flipnote-title-name.mx-auto > h1')?.textContent || '' |
| 71 | + const authorName = document.querySelector('.profile-right > div > span:nth-child(1) > a')?.textContent |
| 72 | + const loopMode = document.querySelector('.controls__group--right > li:nth-child(2) > i')?.className |
| 73 | + const playingKey = document.querySelector('.controls__group--left > li > i')?.className |
| 74 | + const frames = document.querySelector('.controls__frameCounter') |
| 75 | + |
| 76 | + if (!frames) { |
| 77 | + if (flipName.includes(`Flipnote by`)) { |
| 78 | + presenceData.details = 'Untitled Flipnote' |
| 79 | + } |
| 80 | + else { |
| 81 | + presenceData.details = `${flipName}` |
| 82 | + } |
| 83 | + |
| 84 | + presenceData.state = `by: ${authorName}` |
| 85 | + |
| 86 | + if (playingKey === 'fa fa-play') { |
| 87 | + presenceData.smallImageKey = Assets.Pause |
| 88 | + presenceData.smallImageText = 'Paused' |
| 89 | + } |
| 90 | + else if (loopMode === 'far fa-repeat') { |
| 91 | + presenceData.smallImageKey = Assets.Repeat |
| 92 | + presenceData.smallImageText = 'Looping' |
| 93 | + } |
| 94 | + else { |
| 95 | + presenceData.smallImageKey = Assets.Play |
| 96 | + presenceData.smallImageText = 'Playing' |
| 97 | + } |
| 98 | + } |
| 99 | + else { |
| 100 | + if (frames && frames.textContent) { |
| 101 | + const parts = frames.textContent.split('/') |
| 102 | + |
| 103 | + if (parts.length === 2) { |
| 104 | + const currentFrame = parts[0]!.trim() |
| 105 | + const totalFrame = parts[1]!.trim() |
| 106 | + presenceData.name = 'Sudomemo in Filmstrip mode' |
| 107 | + if (flipName.includes(`Flipnote by`)) { |
| 108 | + presenceData.details = `Untitled Flipnote by ${authorName}` |
| 109 | + } |
| 110 | + else { |
| 111 | + presenceData.details = `"${flipName}" by ${authorName}` |
| 112 | + } |
| 113 | + presenceData.state = `Watching frame ${currentFrame} from ${totalFrame}` |
| 114 | + presenceData.smallImageKey = Assets.VideoCall |
| 115 | + presenceData.smallImageText = 'Filmstrip mode' |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + presence.setActivity(presenceData) |
| 122 | +}) |
0 commit comments