AppleMusicToSpotify

append link to Spotify search at Apple Music

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         AppleMusicToSpotify
// @description  append link to Spotify search at Apple Music
// @version      0.2.1
// @namespace    https://github.com/to
// @match        https://music.apple.com/*/album/*
// @match        https://music.apple.com/*/playlist/*
// ==/UserScript==

// original
// https://qiita.com/embokoir/items/d667a6802105b842fb48

let playlist = !!location.href.match('/playlist/');
let artist = document.querySelector('.product-creator').textContent.trim();
let observer = new MutationObserver(records => {
  setTimeout(() => {
    [...document.getElementsByClassName('song-name')].forEach(elmName => {
      let name = elmName.innerText;
      if(playlist)
        artist = elmName.nextElementSibling.textContent.trim();
      
      let elmLink = document.createElement('a');
      elmLink.setAttribute('href', `https://open.spotify.com/search/${artist} ${name}`);
      elmLink.setAttribute('target', '_blank');
      elmLink.style.color = 'hsl(144, 73%, 41%)';
      elmLink.className = elmName.className;
      elmLink.innerText = name;

      elmName.parentNode.replaceChild(elmLink, elmName);
    });
  }, 0);
});

observer.observe(document.body, {
  childList: true
});