AppleMusicToSpotify

append link to Spotify search at Apple Music

  1. // ==UserScript==
  2. // @name AppleMusicToSpotify
  3. // @description append link to Spotify search at Apple Music
  4. // @version 0.2.1
  5. // @namespace https://github.com/to
  6. // @match https://music.apple.com/*/album/*
  7. // @match https://music.apple.com/*/playlist/*
  8. // ==/UserScript==
  9.  
  10. // original
  11. // https://qiita.com/embokoir/items/d667a6802105b842fb48
  12.  
  13. let playlist = !!location.href.match('/playlist/');
  14. let artist = document.querySelector('.product-creator').textContent.trim();
  15. let observer = new MutationObserver(records => {
  16. setTimeout(() => {
  17. [...document.getElementsByClassName('song-name')].forEach(elmName => {
  18. let name = elmName.innerText;
  19. if(playlist)
  20. artist = elmName.nextElementSibling.textContent.trim();
  21. let elmLink = document.createElement('a');
  22. elmLink.setAttribute('href', `https://open.spotify.com/search/${artist} ${name}`);
  23. elmLink.setAttribute('target', '_blank');
  24. elmLink.style.color = 'hsl(144, 73%, 41%)';
  25. elmLink.className = elmName.className;
  26. elmLink.innerText = name;
  27.  
  28. elmName.parentNode.replaceChild(elmLink, elmName);
  29. });
  30. }, 0);
  31. });
  32.  
  33. observer.observe(document.body, {
  34. childList: true
  35. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址