Fixed song titles breaking hyperscript if they included quotes or apostrophes
This commit is contained in:
parent
981ec34e8a
commit
3193f6be52
2 changed files with 15 additions and 2 deletions
|
@ -20,7 +20,10 @@ func NowPlayingHandler(c echo.Context) error {
|
|||
}
|
||||
|
||||
if playing.Item != nil && playing.Playing {
|
||||
return c.String(http.StatusOK, `<div class="indicator-item badge badge-success"><a _="on mouseover put '🔥 Listening to `+playing.Item.Name+" by "+playing.Item.Artists[0].Name+` 🔥' into my.textContent on mouseout put '🔥' into my.textContent" href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
||||
songName := lib.NowPlayingTextFilter(playing.Item.Name)
|
||||
artistName := lib.NowPlayingTextFilter(playing.Item.Artists[0].Name)
|
||||
|
||||
return c.String(http.StatusOK, `<div class="indicator-item badge badge-success"><a _='on mouseover put "🔥 Listening to `+songName+" by "+artistName+` 🔥" into my.textContent on mouseout put "🔥" into my.textContent' href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
||||
} else {
|
||||
return c.String(http.StatusOK, "")
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package lib
|
|||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"atri.dad/lib/pubsub"
|
||||
|
@ -19,6 +20,12 @@ var (
|
|||
once sync.Once
|
||||
)
|
||||
|
||||
func NowPlayingTextFilter(s string) string {
|
||||
s = strings.Replace(s, "'", "'", -1)
|
||||
s = strings.Replace(s, "\"", """, -1)
|
||||
return s
|
||||
}
|
||||
|
||||
func GetOAuth2Config(clientID string, clientSecret string) *oauth2.Config {
|
||||
once.Do(func() {
|
||||
config = &oauth2.Config{
|
||||
|
@ -67,7 +74,10 @@ func CurrentlyPlayingTrackSSE(ctx context.Context, pubSub pubsub.PubSub) error {
|
|||
}
|
||||
|
||||
if playing.Item != nil && playing.Playing {
|
||||
SendSSE(ctx, pubSub, "spotify", `<div class="indicator-item badge badge-success"><a _="on mouseover put '🔥 Listening to `+playing.Item.Name+" by "+playing.Item.Artists[0].Name+` 🔥' into my.textContent on mouseout put '🔥' into my.textContent" href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
||||
songName := NowPlayingTextFilter(playing.Item.Name)
|
||||
artistName := NowPlayingTextFilter(playing.Item.Artists[0].Name)
|
||||
|
||||
return SendSSE(ctx, pubSub, "spotify", `<div class="indicator-item badge badge-success"><a _='on mouseover put "🔥 Listening to `+songName+" by "+artistName+` 🔥" into my.textContent on mouseout put "🔥" into my.textContent' href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
||||
} else {
|
||||
SendSSE(ctx, pubSub, "spotify", "")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue