diff --git a/SpotifyGeniusLyrics.user.js b/SpotifyGeniusLyrics.user.js index c5de1b2..7eb2c9b 100644 --- a/SpotifyGeniusLyrics.user.js +++ b/SpotifyGeniusLyrics.user.js @@ -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 @@ -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) { @@ -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() @@ -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) }