Skip to content

Commit

Permalink
Disable suggestion to submit lyrics on paywall #35
Browse files Browse the repository at this point in the history
Close spotify's lyric view again if there are no lyrics
  • Loading branch information
cvzi committed Jun 3, 2024
1 parent c7f5689 commit bed62f0
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion SpotifyGeniusLyrics.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// @copyright 2020, cuzi (https://github.com/cvzi)
// @supportURL https://github.com/cvzi/Spotify-Genius-Lyrics-userscript/issues
// @icon https://avatars.githubusercontent.com/u/251374?s=200&v=4
// @version 23.5.9
// @version 23.6.0
// @require https://greasyfork.org/scripts/406698-geniuslyrics/code/GeniusLyrics.js
// @require https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js
// @grant GM.xmlHttpRequest
Expand Down Expand Up @@ -142,6 +142,26 @@ async function openAndAskToSubmitSpotifyLyrics (songTitle, songArtistsArr, force
// Wait one second for lyrics to open
window.setTimeout(async function () {
const lyrics = Array.from(document.querySelectorAll('[data-testid="fullscreen-lyric"]')).map(div => div.textContent).join('\n')

// Close lyrics again, if there are no lyrics
if (document.querySelectorAll('[data-testid="fullscreen-lyric"]').length === 0) {
console.debug('Closing lyrics-view, because Spotify has no lyrics either.')
document.querySelector('[data-testid="lyrics-button"]').click()
return
}

// Check if the lyrics are behind a premium modal overlay
for (let p = document.querySelector('[data-testid="fullscreen-lyric"]'); p && p.parentElement; p = p.parentElement) {
if (p.tagName === 'MAIN') {
if (p.querySelector('button span')) {
console.debug('Lyrics are behind paywall, abort submit to genius.')
improveLyricsPaywall()
return
}
break
}
}

if (submitSpotifyLyricsEnabled && lyrics && lyrics.trim()) {
// Add this song to the ignored list so we don't ask again
GM.getValue('submit_spotify_lyrics_ignore', '[]').then(async function (s) {
Expand All @@ -166,6 +186,36 @@ async function openAndAskToSubmitSpotifyLyrics (songTitle, songArtistsArr, force
}, 1000)
}

function improveLyricsPaywall () {
if (!document.querySelector('[data-testid="fullscreen-lyric"]')) {
return
}
let main
for (let p = document.querySelector('[data-testid="fullscreen-lyric"]'); p && p.parentElement; p = p.parentElement) {
if (p.tagName === 'MAIN') {
if (p.querySelector('button span')) {
main = p
break
} else {
return
}
}
}
const modal = main.querySelector('button span').parentNode.parentNode.parentNode
modal.style.width = '50%'
modal.style.height = '30%'
modal.style.top = 'auto'
modal.style.bottom = 0
modal.style.left = 'auto'
modal.style.right = 0
const lyricsHolder = document.querySelector('[data-testid="fullscreen-lyric"]').parentNode
const style = window.getComputedStyle(document.querySelector('[data-testid="fullscreen-lyric"]').firstElementChild, null)
lyricsHolder.className = ''
lyricsHolder.style.fontSize = style.fontSize
lyricsHolder.style.fontWeight = style.fontWeight
lyricsHolder.style.color = style.color
}

function submitLyricsFromMenu () {
genius.f.closeModalUIs()

Expand Down Expand Up @@ -793,4 +843,5 @@ if (document.location.hostname === 'genius.com') {
GM.registerMenuCommand(scriptName + ' - Options', () => genius.f.config())
GM.registerMenuCommand(scriptName + ' - Submit lyrics to Genius', () => submitLyricsFromMenu())
window.setInterval(updateAutoScroll, 1000)
window.setInterval(improveLyricsPaywall, 10000)
}

0 comments on commit bed62f0

Please sign in to comment.