NavidromeGeniusLyrics

Change the semi-useless lyrics button to a GeniusLyrics search

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         NavidromeGeniusLyrics
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Change the semi-useless lyrics button to a GeniusLyrics search
// @author       Max-Pare
// @match        http*://192.168.1.100:4533/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=navidrome.org
// @grant        none
// @license MIT
// ==/UserScript==
// !!! YOU NEED TO CHANGE THE "@match" PROPERTY OF THE SCRIPT TO YOUR ACTUAL SERVER FOR THIS TO EVEN ATTEMPT TO WORK !!!
// e.g.: @match http*://192.168.1.34:4533/* or http*://music.mydomain.com/* or http*://mydomain.com/music/*

const geniusQueryBase = 'https://genius.com/search?q='
const observer = new MutationObserver(callback)
const config = { attributes: false, childList: true, subtree: true }
observer.observe(document.body, config)
function callback () {
    'use strict';
    observer.disconnect()
    let playBar = document.querySelector('section.panel-content')
    if(!playBar) { observer.observe(document.body, config); return }

    let controls = document.querySelector('div.player-content')
    if (!controls) return

    let newLyricsButton = controls.querySelector('span.group.lyric-btn')
    if (!newLyricsButton) return

    newLyricsButton.removeAttribute('onClick')
    newLyricsButton.addEventListener('click', function(event) {
        event.preventDefault();
        event.stopImmediatePropagation();
        let artistElem = document.querySelector('span.songArtist')
        if(!artistElem) return
        let songElem = document.querySelector('span[class*="songTitle"]')
        if(!songElem) return
        let artist = artistElem.textContent;
        let song = songElem.textContent;
        let url = geniusQueryBase + artist + ' - ' + song
        window.open(url, '_blank').focus();
    })
    observer.observe(playBar, config)
}