Spotify - Add label search link

add label search link

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

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