NavidromeGeniusLyrics

Change the semi-useless lyrics button to a GeniusLyrics search

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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)
}