示例#1
0
        private void GPlayWebView_DOMContentLoaded(object sender, WebViewControlDOMContentLoadedEventArgs e)
        {
            // Custom JS function for custom CSS
            string CustomCSSScript = "(function(){" +
                                     "var style=document.getElementById('gmusic_custom_css');" +
                                     "if(!style){ style = document.createElement('STYLE');" +
                                     "style.type='text/css';" +
                                     "style.id='gmusic_custom_css'; " +
                                     "style.innerText = \"" + CustomStyle + "\";" +
                                     "document.getElementsByTagName('HEAD')[0].appendChild(style);" +
                                     "} } )()";

            // Execute the script asychronously
            GPlayWebView.InvokeScriptAsync("eval", new string[] { CustomCSSScript });
        }
示例#2
0
        /// <summary>
        /// Updates RPC content (DO NOT AWAIT)
        /// </summary>
        /// <returns></returns>
        async Task Update()
        {
            while (true)
            {
                try
                {
                    string songName = await GPlayWebView.InvokeScriptAsync("eval", new string[] { "document.getElementById('currently-playing-title').innerText" });

                    string artist = await GPlayWebView.InvokeScriptAsync("eval", new string[] { "document.getElementById('player-artist').innerText" });

                    Title = $"{songName} - Google Play Music";
                    client.SetPresence(new RichPresence()
                    {
                        Details = $"Listening to {songName}",
                        State   = $"by {artist}",
                        Assets  = new Assets()
                        {
                            LargeImageKey  = "google-play-music",
                            LargeImageText = "Google Play Music"
                        }
                    });
                }
                catch
                {
                    Title = $"Google Play Music";
                    client.SetPresence(new RichPresence()
                    {
                        Details = $"Listening to nothing",
                        Assets  = new Assets()
                        {
                            LargeImageKey  = "google-play-music",
                            LargeImageText = "Google Play Music"
                        }
                    });
                }
                await Task.Delay(200);
            }
        }