Discogs/Release/YoutubeSearch

if no yt present, search for possibilities

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         Discogs/Release/YoutubeSearch
// @namespace    https://greasyfork.org/en/scripts/397960
// @version      0.3
// @description  if no yt present, search for possibilities
// @author       denlekke
// @match        http*://www.discogs.com/*release/*
// @match        http*://www.discogs.com/*master/*
// @exclude      http*://www.discogs.com/*/stats/*
// @exclude      http*://www.discogs.com/sell/release/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var youtubePresent = false;
    var youtubeFrame = document.getElementById('youtube_player_wrapper');
    if(youtubeFrame == null){
        //there is no youtube, frame, replace it

        //get release album name
        var pTitle=document.getElementById('profile_title');
        var albumNodes = pTitle.childNodes;
        var album=albumNodes[albumNodes.length-1].textContent.trim();
        if(album===""){
            album=albumNodes[albumNodes.length-2].textContent.trim();
        }
        album = album.replace('/','""');

        var span=pTitle.getElementsByTagName('a')[0].parentNode;
        var artist=span.getAttribute('title').replace(/\(.*\)/g, '');


        //construct the new youtube section
        var videoDiv = document.getElementById('video');
        var youtubeClassSection = document.createElement('div');
        youtubeClassSection.class="section_content toggle_section_content";
        var youtubePlayerWrapper = document.createElement('div');
        youtubePlayerWrapper.id = 'youtube_player_wrapper';
        var youtubeIframe = document.createElement('iframe');
        //youtubeIframe.id = 'youtube_player_placeholder';
        youtubeIframe.setAttribute('id', 'youtube_player_placeholder');
        youtubeIframe.style = '100%; 330px;';
        youtubeIframe.width = '100%';
        youtubeIframe.height = '100%';
        youtubeIframe.src = 'https://www.youtube.com/embed?listType=search&list='+'%22'+encodeURIComponent(artist.trim())+'%22'+'%22'+encodeURIComponent(album.trim())+'%22';

        //on iframe load, show the playlist menu
        //requires cross domain permissions
        /*
        youtubeIframe.addEventListener("load", ev => {
            var iframeDocument = document.getElementById('youtube_player_placeholder');
            console.log("iframedoc"+iframeDocument);
            iframeDocument = iframeDocument.contentWindow;
            console.log("iframedoc"+iframeDocument);
            //var playlistClass = document.querySelector('[aria-label="YouTube Video Player"]');
            //console.log(playlistClass);
            //playlistClass.className = playlistClass.className+' ytp-menu-shown';
            //console.log("class"+playlistClass.className);
        })
*/

        youtubePlayerWrapper.appendChild(youtubeIframe);
        youtubeClassSection.appendChild(youtubePlayerWrapper)
        videoDiv.appendChild(youtubeClassSection);
    }
    else{
        //there is a youtube frame, do nothing
        console.log("yt present");
    }

})();