1+ var statusIcon = document . getElementById ( "statusIcon" ) ;
2+ var spotifyListening = document . getElementById ( "spotifyListening" ) ;
3+ var visualStudioCodePlaying = document . getElementById ( "visualStudioCodePlaying" ) ;
4+ var netflixWatching = document . getElementById ( "netflixWatching" ) ;
5+ var disneyPlusWatching = document . getElementById ( "disneyPlusWatching" ) ;
6+ var activitiesStatus = document . getElementById ( "activitiesStatus" ) ;
7+ var discordStatus = document . getElementById ( "discordStatus" ) ;
8+
9+ const lanyard = new WebSocket ( "wss://api.lanyard.rest/socket" ) ;
10+
11+ var api = { } ;
12+ var received = false ;
13+
14+ lanyard . onopen = function ( ) {
15+ lanyard . send (
16+ JSON . stringify ( {
17+ op : 2 ,
18+ d : {
19+ subscribe_to_id : "354343248698802187" ,
20+ } ,
21+ } )
22+ ) ;
23+ } ;
24+
25+ setInterval ( ( ) => {
26+ if ( received ) {
27+ lanyard . send (
28+ JSON . stringify ( {
29+ op : 3 ,
30+ } )
31+ ) ;
32+ }
33+ } , 30000 ) ;
34+
35+ lanyard . onmessage = function ( event ) {
36+ received = true ;
37+ api = JSON . parse ( event . data ) ;
38+
39+ if ( api . t === "INIT_STATE" || api . t === "PRESENCE_UPDATE" ) {
40+ update_presence ( ) ;
41+ }
42+ } ;
43+
44+ function update_presence ( ) {
45+
46+
47+ if ( statusIcon != null ) {
48+ update_status ( api . d . discord_status ) ;
49+ }
50+
51+ var figmaAppID = "866719067092418580"
52+ var figmaActivity = api . d . activities . find ( activity => activity . application_id == figmaAppID )
53+
54+ if ( figmaActivity ) {
55+ var figmaDetails = figmaActivity . details
56+ var figmaState = figmaActivity . state
57+
58+ figmaPlaying . innerHTML = `
59+ <a href="javascript:void(0)">
60+ <div class="card rounded-custom h-full">
61+ <div class="p-4 flex space-x-2 items-center overflow-hidden">
62+ <img draggable="false" src="/assets/img/figma.png" alt="IMG" class="rounded-custom cardImage"
63+ width="60" height="60">
64+ <p class="normalText ml-3 opacity-80">${ figmaState || "Figma" } <br><span class="normalText opacity-60">${ figmaDetails || " " } </span></p>
65+ </div>
66+ </div>
67+ </a>` ;
68+ } else {
69+ figmaPlaying . innerHTML = `` ;
70+ document . getElementById ( "figmaPlaying" ) . style . display = "none" ;
71+ }
72+
73+ var vsCodeAppID = "383226320970055681"
74+ var vsCodeActivity = api . d . activities . find ( activity => activity . application_id == vsCodeAppID )
75+
76+ if ( vsCodeActivity ) {
77+ var vsCodeDetails = vsCodeActivity . details
78+ var vsCodeState = vsCodeActivity . state
79+
80+ visualStudioCodePlaying . innerHTML = `
81+ <a href="javascript:void(0)">
82+ <div class="card rounded-custom h-full">
83+ <div class="p-4 flex space-x-2 items-center overflow-hidden">
84+ <img draggable="false" src="/assets/img/visualStudioCode.png" alt="IMG" class="rounded-custom cardImage"
85+ width="60" height="60">
86+ <p class="normalText ml-3 opacity-80">${ vsCodeState || "VS Code" } <br><span class="normalText opacity-60">${ vsCodeDetails || " " } </span></p>
87+ </div>
88+ </div>
89+ </a>` ;
90+ } else {
91+ visualStudioCodePlaying . innerHTML = `` ;
92+ document . getElementById ( "visualStudioCodePlaying" ) . style . display = "none" ;
93+ }
94+
95+ var netflixAppID = "926541425682829352"
96+ var netflixActivity = api . d . activities . find ( activity => activity . application_id == netflixAppID )
97+
98+ if ( netflixActivity ) {
99+ var netflixImage = netflixActivity . assets . large_image
100+ var netflixImageLink = netflixImage . substring ( netflixImage . indexOf ( "https/" ) ) ;
101+ var netflixImageLinkRevised = netflixImageLink . replace ( 'https/' , 'https://' ) ;
102+
103+ netflixWatching . innerHTML = `
104+ <a href="javascript:void(0)">
105+ <div class="card rounded-custom h-full">
106+ <div class="p-4 flex space-x-2 items-center overflow-hidden">
107+ <img draggable="false" src="${ netflixImageLinkRevised || "/assets/img/netflix.png" } " alt="IMG" class="rounded-custom cardImage"
108+ width="60" height="60">
109+ <p class="normalText ml-3 opacity-80">${ netflixActivity . details || "Netflix" } <br><span class="normalText opacity-60">${ netflixActivity . state || " " } </span></p>
110+ </div>
111+ </div>
112+ </a>` ;
113+ } else {
114+ netflixWatching . innerHTML = `` ;
115+ document . getElementById ( "netflixWatching" ) . style . display = "none" ;
116+ }
117+
118+ var disneyPlusAppID = "630236276829716483"
119+ var disneyPlusActivity = api . d . activities . find ( activity => activity . application_id == disneyPlusAppID )
120+
121+ if ( disneyPlusActivity ) {
122+ disneyPlusWatching . innerHTML = `
123+ <a href="javascript:void(0)">
124+ <div class="card rounded-custom h-full">
125+ <div class="p-4 flex space-x-2 items-center overflow-hidden">
126+ <img draggable="false" src="/assets/img/disneyPlus.png" alt="IMG" class="rounded-custom cardImage"
127+ width="60" height="60">
128+ <p class="normalText ml-3 opacity-80">${ disneyPlusActivity . details || "Disney+" } <br><span class="normalText opacity-60">${ disneyPlusActivity . state || " " } </span></p>
129+ </div>
130+ </div>
131+ </a>` ;
132+ } else {
133+ disneyPlusWatching . innerHTML = `` ;
134+ document . getElementById ( "disneyPlusWatching" ) . style . display = "none" ;
135+ }
136+
137+ if ( api . d . listening_to_spotify === true ) {
138+ const start = api . d . spotify . timestamps . start ;
139+ const end = api . d . spotify . timestamps . end ;
140+ const duration = end - start ;
141+ const now = Date . now ( ) ;
142+ const progress = Math . min ( now - start , duration ) ;
143+ const percentage = ( progress / duration ) * 100 ;
144+
145+ const artist = api . d . spotify . artist . replace ( / \; / g, "," ) ;
146+ const song = `${ api . d . spotify . song } ` ;
147+ const albumArt = api . d . spotify . album_art_url || "/assets/img/spotify.png" ;
148+
149+ spotifyListening . style . display = "" ; // tekrar görünür yap
150+ spotifyListening . innerHTML = `
151+ <a href="https://open.spotify.com/track/${ api . d . spotify . track_id } " target="_blank">
152+ <div class="card rounded-custom h-full">
153+ <div class="p-4 flex items-center space-x-4 overflow-hidden">
154+ <div class="relative flex items-center justify-center cardImage animate-pulse">
155+ <svg class="absolute cardImage" viewBox="0 0 100 100">
156+ <circle cx="50" cy="50" r="45" stroke="rgba(0, 0, 0, 0.5)" stroke-width="6" fill="none"/>
157+ <circle id="spotifyRing" cx="50" cy="50" r="45" stroke="#1DB954" stroke-width="6" fill="none"
158+ stroke-linecap="round" stroke-dasharray="282.6" stroke-dashoffset="282.6" transform="rotate(-90 50 50)"/>
159+ </svg>
160+ <img src="${ albumArt } " alt="Album Art" class="rounded-full object-cover cardImage">
161+ </div>
162+ <p class="normalText opacity-80">
163+ ${ song } <br>
164+ <span class="normalText opacity-60">${ artist } </span>
165+ </p>
166+ </div>
167+ </div>
168+ </a>
169+ ` ;
170+
171+ function updateSpotifyRing ( ) {
172+ const now = Date . now ( ) ;
173+ const progress = Math . min ( now - start , duration ) ;
174+ const percent = progress / duration ;
175+ const ring = document . getElementById ( "spotifyRing" ) ;
176+ if ( ring ) {
177+ const totalLength = 2 * Math . PI * 45 ;
178+ ring . style . strokeDashoffset = totalLength * ( 1 - percent ) ;
179+ }
180+ }
181+
182+ updateSpotifyRing ( ) ;
183+ if ( window . spotifyRingInterval ) clearInterval ( window . spotifyRingInterval ) ;
184+ window . spotifyRingInterval = setInterval ( updateSpotifyRing , 1000 ) ;
185+
186+ } else {
187+ spotifyListening . innerHTML = `` ;
188+ spotifyListening . style . display = "none" ;
189+ if ( window . spotifyRingInterval ) clearInterval ( window . spotifyRingInterval ) ;
190+ }
191+
192+
193+
194+
195+ function update_status ( status ) {
196+ if ( statusIcon == null ) return ;
197+
198+ if ( status === "online" ) {
199+ statusIcon . innerHTML = "online" ;
200+ } else if ( status === "idle" ) {
201+ statusIcon . innerHTML = "idle" ;
202+ } else if ( status === "dnd" ) {
203+ statusIcon . innerHTML = "dnd" ;
204+ } else if ( status === "offline" ) {
205+ statusIcon . innerHTML = "offline" ;
206+ } else {
207+ statusIcon . innerHTML = "offline" ;
208+ }
209+ }
210+
211+ setInterval ( function ( ) {
212+ if ( api . d . listening_to_spotify == false && api . d . activities . find ( activity => activity . application_id == disneyPlusAppID ) == undefined && api . d . activities . find ( activity => activity . application_id == netflixAppID ) == undefined && api . d . activities . find ( activity => activity . application_id == vsCodeAppID ) == undefined ) {
213+ activitiesStatus . innerHTML = `<span class="normalText opacity-80">There are currently no activity.</span>` ;
214+ } else {
215+ activitiesStatus . innerHTML = `` ;
216+ document . getElementById ( "activitiesStatus" ) . style . display = "none" ;
217+ }
218+ } , 1000 )
219+
220+ }
221+
222+
223+ lanyard . onclose = function ( ) {
224+ console . warn ( "WebSocket closed, reconnecting..." ) ;
225+ setTimeout ( ( ) => {
226+ location . reload ( ) ;
227+ } , 2000 ) ;
228+ } ;
229+
230+ if ( lanyard . readyState === WebSocket . OPEN ) {
231+ lanyard . send ( JSON . stringify ( { op : 3 } ) ) ;
232+ }
0 commit comments