Search Openings/Endings on Youtube - MAL

Click on the opening/ending music title to search for the music title on youtube on a new tab.

As of 04.08.2021. See ბოლო ვერსია.

// ==UserScript==
// @name        Search Openings/Endings on Youtube - MAL
// @namespace   Search_Ops_Ends
// @version     0.4
// @description Click on the opening/ending music title to search for the music title on youtube on a new tab.
// @author      hacker09
// @match       https://myanimelist.net/anime/*
// @match       https://myanimelist.net/manga/*
// @icon        https://www.google.com/s2/favicons?domain=myanimelist.net
// @run-at      document-end
// ==/UserScript==

(function() {
  'use strict';
  if (document.querySelectorAll('span[class*="theme-song"]').length !== 0) //If there's at least one op/end listed on the page
  { //Starts the if condition
    document.querySelectorAll('span[class*="theme-song"]').forEach(function(el) { //For each op/end
      var title = el.innerText.split(': '); //Save the op/end title on a variable

      if (title[1] !== undefined) //If there's a number: in front of the op/end title
      { //Starts the if condition
        title = title[1].split('(ep')[0].trim(); //Save the op/end title on a variable
      } //Finishes the if condition
      else //If there's no number: in front of the op/end title
      { //Starts the else condition
        title = title[0].split('(ep')[0].trim(); //Save the op/end title on a variable
      } //Finishes the else condition

      el.style.cursor = 'pointer'; //Make the op/end title element look like it's clickable

      el.onclick = function() //When the op/end title is clicked
      { //Starts the onclick function
        window.open('https://www.youtube.com/results?search_query=' + title, 'blank'); //Search the music title on youtube on a new tab
      }; //Finishes the onclick function

      el.onmouseout = function() //When the op/end title is unhovered
      { //Starts the onmouseout function
        this.style.color = ''; //Readd the default color
      }; //Finishes the onmouseout function

      el.onmouseover = function() //When the op/end title is hovered
      { //Starts the onmouseover function
        this.style.color = '#6386d5'; //Change the default text color to blue
      }; //Finishes the onmouseover function

    }); //Finishes the for each condition
  } //Finishes the if condition
})();