-
Notifications
You must be signed in to change notification settings - Fork 0
/
LFM-Genius-Icon.user.js
46 lines (39 loc) · 1.96 KB
/
LFM-Genius-Icon.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ==UserScript==
// @name LFM-Genius-Icon
// @namespace https://www.last.fm/
// @version 1.0.0
// @description Adds an icon under the title of a song in Last.fm to open the page of the song in Genius.com.
// @author Megane0103
// @match https://www.last.fm/*
// @grant none
// @license MIT; https://github.com/Megane0103/LFM-Genius-Icon/blob/main/LICENSE
// @copyright 2023, Megane0103 (https://github.com/Megane0103)
// ==/UserScript==
(function() {
'use strict';
// Getting the song title and artist name from the page URL
const path = window.location.pathname.split('/');
let artistName = decodeURIComponent(path[2]).replace(/\+/g, '-').replace(/\s+/g, '-').toLowerCase();
let songTitle = document.querySelector('.header-new-title').textContent;
songTitle = songTitle.replace(/\s+/g, '-').toLowerCase();
// Removing diacritics from artistName and songTitle
artistName = removeDiacritics(artistName);
songTitle = removeDiacritics(songTitle);
// Removing apostrophes and tildes from artistName
artistName = artistName.replace(/['~]/g, '');
// Creating a new image element
const geniusIcon = document.createElement('img');
geniusIcon.src = 'https://user-images.githubusercontent.com/99014543/224570329-0acca5ae-1ccf-46b2-99b4-5be75a0c494e.png';
geniusIcon.style.height = '20px';
geniusIcon.style.width = '20px';
// Adding a listener to the icon to open the Genius.com page for the song
geniusIcon.addEventListener('click', function() {
const url = `https://genius.com/${encodeURIComponent(artistName)}-${encodeURIComponent(songTitle).replace(/[^\w\-]+/g, '')}-lyrics`;
window.open(url);
});
// Inserting the icon under the song title on the page
document.querySelector('.header-new-title').insertAdjacentElement('afterend', geniusIcon);
function removeDiacritics(str) {
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}
})();