@@ -3,157 +3,137 @@ const presence = new Presence({
33} )
44const browsingTimestamp = Math . floor ( Date . now ( ) / 1000 )
55
6- presence . on ( 'UpdateData' , ( ) => {
6+ presence . on ( 'UpdateData' , async ( ) => {
77 const presenceData : PresenceData = {
88 largeImageKey : 'https://cdn.rcd.gg/PreMiD/websites/K/Ko-Fi/assets/logo.png' ,
99 startTimestamp : browsingTimestamp ,
1010 }
11- if ( document . location . pathname === '/' ) {
11+
12+ const { pathname, href } = document . location
13+ const buttons = await presence . getSetting < boolean > ( 'buttons' )
14+
15+ if ( pathname === '/' ) {
1216 presenceData . details = 'Viewing the home page.'
1317 }
14- else if ( document . location . pathname . startsWith ( '/dashboard/' ) ) {
18+ else if ( pathname . startsWith ( '/dashboard/' ) ) {
1519 presenceData . details = 'Managing the settings of:'
16- presenceData . state = document
17- . querySelector (
18- 'body > div.app > header > ul.navbar-nav.ml-auto.d-none.d-sm-inline-block > div > div' ,
19- )
20- ?. textContent
21- ?. trim ( )
22- }
23- else if (
24- document . location . pathname . toLowerCase ( ) . startsWith ( '/account/register' )
25- ) {
20+ presenceData . state = document . querySelector ( 'body > div.app > header > ul.navbar-nav.ml-auto.d-none.d-sm-inline-block > div > div' ) ?. textContent ?. trim ( )
21+ }
22+ else if ( pathname . toLowerCase ( ) . startsWith ( '/account/register' ) ) {
2623 presenceData . details = 'Registering...'
2724 }
28- else if (
29- document . location . pathname . toLowerCase ( ) . startsWith ( '/account/login' )
30- || document . location . pathname
31- . toLowerCase ( )
32- . startsWith ( '/account/externallogincallback' )
33- ) {
25+ else if ( pathname . toLowerCase ( ) . startsWith ( '/account/login' ) || pathname . toLowerCase ( ) . startsWith ( '/account/externallogincallback' ) ) {
3426 presenceData . details = 'Logining in...'
3527 }
36- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/account/' ) ) {
28+ else if ( pathname . toLowerCase ( ) . startsWith ( '/account/' ) ) {
3729 presenceData . details = 'Setting up account...'
3830 }
39- else if ( document . location . pathname . startsWith ( '/gold' ) ) {
31+ else if ( pathname . startsWith ( '/gold' ) ) {
4032 presenceData . details = 'Viewing the Gold plan.'
4133 }
42- else if ( document . location . pathname . startsWith ( '/art' ) ) {
34+ else if ( pathname . startsWith ( '/art' ) ) {
4335 presenceData . details = 'Viewing art creations.'
4436 }
45- else if ( document . location . pathname . startsWith ( '/cosplay' ) ) {
37+ else if ( pathname . startsWith ( '/cosplay' ) ) {
4638 presenceData . details = 'Viewing cosplay creations.'
4739 }
48- else if ( document . location . pathname . startsWith ( '/commissionsopen' ) ) {
40+ else if ( pathname . startsWith ( '/commissionsopen' ) ) {
4941 presenceData . details = 'Viewing open commissions.'
5042 }
51- else if (
52- document . location . pathname . toLowerCase ( ) . startsWith ( '/home/featured' )
53- ) {
43+ else if ( pathname . toLowerCase ( ) . startsWith ( '/home/featured' ) ) {
5444 presenceData . details = 'Viewing featured creators.'
5545 }
56- else if ( document . location . pathname . toLowerCase ( ) === '/explore' ) {
46+ else if ( pathname . toLowerCase ( ) === '/explore' ) {
5747 presenceData . details = 'Viewing the explore page.'
5848 }
59- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/blog/' ) ) {
49+ else if ( pathname . toLowerCase ( ) . startsWith ( '/blog/' ) ) {
6050 presenceData . details = 'Creating a blog post...'
6151 }
62- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/manage' ) ) {
52+ else if ( pathname . toLowerCase ( ) . startsWith ( '/manage' ) ) {
6353 presenceData . details = 'Managing Ko-Fi'
6454 }
65- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/settings' ) ) {
55+ else if ( pathname . toLowerCase ( ) . startsWith ( '/settings' ) || pathname . toLowerCase ( ) . startsWith ( '/discord /settings' ) ) {
6656 presenceData . details = 'Adjusting user settings...'
6757 }
68- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/newsfeed ' ) ) {
58+ else if ( pathname . toLowerCase ( ) . startsWith ( '/newsfeed' ) || pathname . toLowerCase ( ) . startsWith ( '/feed ' ) ) {
6959 presenceData . details = 'Viewing the newsfeed...'
7060 }
71- else if (
72- document . location . pathname . toLowerCase ( ) . startsWith ( '/my-supporters' )
73- ) {
61+ else if ( pathname . toLowerCase ( ) . startsWith ( '/my-supporters' ) ) {
7462 presenceData . details = 'Viewing supporters...'
7563 }
76- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/streamalerts' ) ) {
64+ else if ( pathname . toLowerCase ( ) . startsWith ( '/messages' ) ) {
65+ presenceData . details = 'Viewing messages...'
66+ }
67+ else if ( pathname . toLowerCase ( ) . startsWith ( '/streamalerts' ) ) {
7768 presenceData . details = 'Viewing stream alerts.'
7869 }
79- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/shop' ) ) {
70+ else if ( pathname . toLowerCase ( ) . startsWith ( '/promote' ) ) {
71+ presenceData . details = 'Viewing promote page.'
72+ }
73+ else if ( pathname . toLowerCase ( ) . startsWith ( '/discount' ) ) {
74+ presenceData . details = 'Viewing discounts page.'
75+ }
76+ else if ( pathname . toLowerCase ( ) . startsWith ( '/memberships/settings' ) ) {
77+ presenceData . details = 'Adjusting membership settings...'
78+ }
79+ else if ( pathname . toLowerCase ( ) . startsWith ( '/shop' ) ) {
8080 presenceData . details = 'Viewing shop.'
8181 }
82- else if ( document . location . pathname . toLowerCase ( ) === '/about' ) {
82+ else if ( pathname . toLowerCase ( ) === '/about' ) {
8383 presenceData . details = 'Viewing Ko-Fi\'s About Page'
8484 }
85- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/s/' ) ) {
85+ else if ( pathname . toLowerCase ( ) . startsWith ( '/s/' ) ) {
8686 try {
87- presenceData . details = `Viewing ${ document
88- . querySelector (
89- '#shop-item-detail > div > div.kfds-lyt-between-algn-top-row-to-col.kfds-c-sticky > div.sidebar.kfds-c-sticky-wrapper.kfds-c-order-2.kfds-c-shop-detail-wrapper > div.kfds-lyt-width-100.kfds-c-lyt-pdg-16-24.kfds-c-shop-detail-column-control > span' ,
90- )
91- ?. textContent
92- ?. trim ( ) } `
93- presenceData . state = `By ${ document
94- . querySelector (
95- '#shop-item-detail > div > div.kfds-lyt-between-algn-top-row-to-col.kfds-c-sticky > div.sidebar.kfds-c-sticky-wrapper.kfds-c-order-2.kfds-c-shop-detail-wrapper > div.kfds-lyt-width-100.kfds-c-lyt-pdg-16-24.kfds-c-shop-detail-column-control > div > a > div > span:nth-child(1)' ,
96- )
97- ?. textContent
98- ?. trim ( ) } `
99- presenceData . buttons = [
100- {
101- label : 'View Item' ,
102- url : `https://ko-fi.com/s/${
103- document . location . pathname . split ( '/' ) [ 2 ]
104- } ?ref=premid_discord_presence`,
105- } ,
106- ]
87+ presenceData . details = `Viewing ${ document . querySelector ( '#shop-item-detail > div > div.kfds-lyt-between-algn-top-row-to-col.kfds-c-sticky > div.sidebar.kfds-c-sticky-wrapper.kfds-c-order-2.kfds-c-shop-detail-wrapper > div.kfds-lyt-width-100.kfds-c-lyt-pdg-16-24.kfds-c-shop-detail-column-control > span' ) ?. textContent ?. trim ( ) } `
88+ presenceData . state = `By ${ document . querySelector ( '#body-content font' ) ?. textContent ?. trim ( ) } `
89+
90+ if ( buttons ) {
91+ presenceData . buttons = [
92+ {
93+ label : 'View Item' ,
94+ url : href ,
95+ } ,
96+ ]
97+ }
10798 }
10899 catch {
109100 presenceData . details = 'Viewing a shop item.'
110101 }
111102 }
112- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/summary' ) ) {
103+ else if ( pathname . toLowerCase ( ) . startsWith ( '/summary' ) ) {
113104 presenceData . details = 'Viewing payment summary.'
114105 }
115- else if (
116- document . location . pathname . toLowerCase ( ) . startsWith ( '/home/coffeeshop' )
117- ) {
106+ else if ( pathname . toLowerCase ( ) . startsWith ( '/home/coffeeshop' ) ) {
118107 presenceData . details = 'Just bought someone coffee!'
119108 }
120- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/home/about' ) ) {
109+ else if ( pathname . toLowerCase ( ) . startsWith ( '/home/about' ) ) {
121110 presenceData . details = 'Viewing Ko-Fi\'s About Page'
122111 }
123- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/home' ) ) {
112+ else if ( pathname . toLowerCase ( ) . startsWith ( '/home' ) ) {
124113 presenceData . details = 'Viewing the home page.'
125114 }
126- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/post' ) ) {
115+ else if ( pathname . toLowerCase ( ) . startsWith ( '/post' ) ) {
127116 presenceData . details = 'Viewing a post.'
128117 try {
129118 presenceData . details = 'Viewing a post:'
130- presenceData . state = document
131- . querySelector (
132- '#body-content > div > div.wrapper.wrapper-content.article > div > div > div > div > div:nth-child(4) > div > h1' ,
133- )
134- ?. textContent
135- ?. trim ( )
136- presenceData . buttons = [
137- {
138- label : 'View Post' ,
139- url : `https://ko-fi.com/post/${
140- document . location . pathname . split ( '/' ) [ 2 ]
141- } ?ref=premid_discord_presence`,
142- } ,
143- ]
119+ presenceData . state = document . querySelector ( 'h1' ) ?. textContent ?. trim ( )
120+
121+ if ( buttons ) {
122+ presenceData . buttons = [
123+ {
124+ label : 'View Post' ,
125+ url : href ,
126+ } ,
127+ ]
128+ }
144129 }
145130 catch {
146131 presenceData . details = 'Viewing a post.'
147132 }
148133 }
149- else if ( document . location . pathname . toLowerCase ( ) . startsWith ( '/album' ) ) {
134+ else if ( pathname . toLowerCase ( ) . startsWith ( '/album' ) ) {
150135 try {
151- const user = document
152- . querySelector (
153- '#body-content > div > div > div:nth-child(2) > div > a > name' ,
154- )
155- ?. textContent
156- ?. trim ( )
136+ const user = document . querySelector ( 'name' ) ?. textContent ?. trim ( )
157137 presenceData . details = 'Viewing an album.'
158138 if ( user !== 'undefined' ) {
159139 presenceData . details = 'Viewing a users album:'
@@ -164,43 +144,59 @@ presence.on('UpdateData', () => {
164144 presenceData . details = 'Viewing an album.'
165145 }
166146 }
167- else if ( document . location . pathname . toLowerCase ( ) === '/404.html' ) {
147+ else if ( pathname . toLowerCase ( ) . startsWith ( '/polls' ) ) {
148+ try {
149+ const user = document . querySelector ( 'name' ) ?. textContent ?. trim ( )
150+ presenceData . details = 'Viewing an poll.'
151+
152+ if ( buttons ) {
153+ presenceData . buttons = [
154+ {
155+ label : 'View Poll' ,
156+ url : href ,
157+ } ,
158+ ]
159+ }
160+ if ( user !== 'undefined' ) {
161+ presenceData . details = 'Viewing a users poll:'
162+ presenceData . state = user
163+ }
164+ }
165+ catch {
166+ presenceData . details = 'Viewing an poll.'
167+ }
168+ }
169+ else if ( pathname . toLowerCase ( ) === '/404.html' ) {
168170 presenceData . details = 'Oh No! Page Not Found.'
169171 }
170172 else {
171173 try {
172- const user = document
173- . querySelector (
174- '#profile-header-v2 > div > div.kfds-lyt-column.kfds-lyt-width-100.kfds-c-header-showmobile-at-736 > div.kfds-lyt-row-start.kfds-lyt-width-100 > div > div.kfds-font-size-22.kfds-font-bold > span' ,
175- )
176- ?. textContent
177- ?. trim ( )
178- const userSplit = document . location . pathname . split ( '/' )
179- // userFixed = user.toLowerCase().split(" ").join("");
180- // console.log(userFixed)
174+ const user = document . querySelector ( '#displayName' ) ?. textContent ?. trim ( )
175+ const userSplit = pathname . split ( '/' ) [ 1 ]
181176
182177 if ( user !== 'undefined' ) {
183178 presenceData . details = 'Viewing this users page:'
184179 presenceData . state = user
185- presenceData . buttons = [
186- {
187- label : 'View Page' ,
188- url : `https://ko-fi.com/${ userSplit [ 1 ] } ?ref=premid_discord_presence` ,
189- } ,
190- ]
180+
181+ if ( buttons ) {
182+ presenceData . buttons = [
183+ {
184+ label : 'View Page' ,
185+ url : `https://ko-fi.com/${ userSplit } ` ,
186+ } ,
187+ ]
188+ }
191189 }
192190
193- if ( document . location . pathname . startsWith ( `/${ userSplit [ 1 ] } /gallery` ) )
191+ if ( pathname . startsWith ( `/${ userSplit } /gallery` ) )
194192 presenceData . details = 'Viewing this users gallery:'
195- else if ( document . location . pathname . startsWith ( `/${ userSplit [ 1 ] } /posts` ) )
193+ else if ( pathname . startsWith ( `/${ userSplit } /posts` ) )
196194 presenceData . details = 'Viewing this users posts:'
197- else if ( document . location . pathname . startsWith ( `/${ userSplit [ 1 ] } /shop` ) )
195+ else if ( pathname . startsWith ( `/${ userSplit } /shop` ) )
198196 presenceData . details = 'Viewing this users shop:'
199- else if (
200- document . location . pathname . startsWith ( `/${ userSplit [ 1 ] } /commissions` )
201- )
197+ else if ( pathname . startsWith ( `/${ userSplit } /commissions` ) )
202198 presenceData . details = 'Viewing this users commissions:'
203- else if ( document . location . pathname . startsWith ( `/${ userSplit [ 1 ] } /tiers` ) )
199+ else if ( pathname . startsWith ( `/${ userSplit } /tiers` ) )
204200 presenceData . details = 'Viewing this users tier options:'
205201 }
206202 catch {
0 commit comments