Spotify - Add label search link

add label search link

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Spotify - Add label search link
// @description  add label search link
// @author       to
// @namespace    https://github.com/to
// @version      0.1
// @license      MIT
// @match        https://open.spotify.com/*
// @icon         https://www.google.com/s2/favicons?domain=spotify.com
// ==/UserScript==

// ページ遷移を監視する
function watchLocation(match, callback) {
  let page;
  setInterval(() => {
    // ページ遷移が発生したか?
    if (page != location.href) {
      page = location.href;

      // 対象のページか?
      if (match.test(page))
        callback(page);
    }
  }, 500);
}

watchLocation(/\/album\//, () => {
  // DOMへの反映を待つ
  let timer = setInterval(() => {
    // 権利表記を繰り返す
    let pre;
    [...document.querySelectorAll('div[aria-colcount] + div p')].map(elmRight => {
      // 表記をクリアする
      let right = elmRight.textContent.replaceAll(/(\℗ |© |(\(P\))?\d{4} )/g, '');
      elmRight.innerHTML = '';

      // 同一の内容の場合、省略する
      if (pre == right) return;
      pre = right

      // 各権利者を繰り返す
      right.split(/ ?\/ ?/).map((label, i) => {
        i && elmRight.appendChild(document.createTextNode(" / "));

        // 検索リンクを追加する
        let elmLink = document.createElement('a');
        elmLink.href = `https://open.spotify.com/search/label:"${label}"`;
        elmLink.target = '_blank';
        elmLink.textContent = label;

        elmRight.appendChild(elmLink);
      });

      // 反映の監視を終了する(重複クリアは許容する)
      clearInterval(timer);
    });
  }, 100);
});