Add Spotify and YouTube Buttons to Shazam

Adds Spotify and YouTube buttons to Shazam track pages

  1. // ==UserScript==
  2. // @name Add Spotify and YouTube Buttons to Shazam
  3. // @author tanso
  4. // @description Adds Spotify and YouTube buttons to Shazam track pages
  5. // @version 1.1
  6. // @license MIT
  7. // @match https://www.shazam.com/*
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/1467885
  10. // ==/UserScript==
  11. (() => {
  12. 'use strict';
  13.  
  14. const addSpotifyButton = () => {
  15. const shareButton = document.querySelector('.TrackPageHeader_share__q1WWs');
  16. if (!shareButton) return;
  17.  
  18. const spotifyButton = shareButton.cloneNode(true);
  19. const spotifyButtonLink = spotifyButton.querySelector('a');
  20.  
  21. spotifyButtonLink.innerHTML = `<span class="Button-module_label__k1Dkf">
  22. <img src="https://storage.googleapis.com/pr-newsroom-wp/1/2023/05/Spotify_Primary_Logo_RGB_Green.png"
  23. style="width: 40px; height: 40px; margin-right: 15px; vertical-align: middle;">Spotify</span>`;
  24.  
  25. spotifyButtonLink.style.padding = "7px 30px 7px 7px";
  26. spotifyButtonLink.querySelector('.Button-module_label__k1Dkf').style.cssText += 'color: white !important;';
  27. spotifyButtonLink.style.backgroundColor = '#101218';
  28.  
  29. const songTitle = document.querySelector('.TrackPageHeader_title__wGI_Q')?.textContent;
  30. const artistName = document.querySelector('meta[itemprop="name"]')?.content;
  31. if (!songTitle || !artistName) return;
  32.  
  33. const encodedSearch = encodeURIComponent(`${artistName} ${songTitle}`);
  34.  
  35. spotifyButtonLink.href = `https://open.spotify.com/search/${encodedSearch}`;
  36. spotifyButtonLink.target = '_blank';
  37.  
  38. shareButton.parentNode.insertBefore(spotifyButton, shareButton);
  39. };
  40.  
  41. const addYouTubeButton = () => {
  42. const shareButton = document.querySelector('.TrackPageHeader_share__q1WWs');
  43. if (!shareButton) return;
  44.  
  45. const youtubeButton = shareButton.cloneNode(true);
  46. const youtubeButtonLink = youtubeButton.querySelector('a');
  47.  
  48. youtubeButtonLink.innerHTML = `<span class="Button-module_label__k1Dkf">
  49. <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/YouTube_icon_%282013-2017%29.png/800px-YouTube_icon_%282013-2017%29.png"
  50. style="width: 40px; height: 40px; margin-right: 15px; vertical-align: middle; border-radius: 50%;">YouTube</span>`;
  51.  
  52. youtubeButtonLink.style.padding = "7px 30px 7px 7px";
  53. youtubeButtonLink.querySelector('.Button-module_label__k1Dkf').style.cssText += 'color: white !important;';
  54. youtubeButtonLink.style.backgroundColor = '#2E2E2E';
  55.  
  56. const songTitle = document.querySelector('.TrackPageHeader_title__wGI_Q')?.textContent;
  57. const artistName = document.querySelector('meta[itemprop="name"]')?.content;
  58. if (!songTitle || !artistName) return;
  59.  
  60. const encodedSearch = encodeURIComponent(`${artistName} ${songTitle}`);
  61.  
  62. youtubeButtonLink.href = `https://www.youtube.com/results?search_query=${encodedSearch}`;
  63. youtubeButtonLink.target = '_blank';
  64.  
  65. shareButton.parentNode.insertBefore(youtubeButton, shareButton.nextSibling);
  66. };
  67.  
  68. window.addEventListener('load', () => {
  69. addSpotifyButton();
  70. addYouTubeButton();
  71. });
  72. })();