IMDB Video Player - 2embed (play streaming videos from IMDb)

Add video player from 2embed.ru directly into IMDB movie/serie webpage.

当前为 2021-12-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         IMDB Video Player - 2embed (play streaming videos from IMDb)
// @name:fr      Lecture en Streaming de film et séries IMDb
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  Add video player from 2embed.ru directly into IMDB movie/serie webpage.
// @description:fr  Lis le media en streaming directement sur IMDb.
// @author       Guillome91
// @license      MIT
// @match        https://www.imdb.com/title/*
// @icon         https://www.google.com/s2/favicons?domain=imdb.com
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    const currentUrl = document.URL;
    const api = currentUrl.split('/')[4];
    console.log(api);
    var location, player_url;
    if(document.title.includes('Series')){
        function makecall(callback){
            GM_xmlhttpRequest({
                method: "GET",
                url: "https://api.themoviedb.org/3/find/"+api+"?api_key=8d6d91941230817f7807d643736e8a49&language=en-US&external_source=imdb_id",
                onload: function(response) {
                    let tmdb_id = JSON.parse(response.responseText).tv_results[0].id;
                    console.log("tmbd_id= "+tmdb_id);
                    callback(tmdb_id);
                }
            });
        }
        function process_response(tmdb_id){
            location = document.querySelector('main');
            player_url = "https://www.2embed.ru/library/tv/"+tmdb_id;
            let div = document.createElement("div");
            div.setAttribute('style','overflow: hidden; margin: 15px auto; max-width: 762px;');
            let ifr = document.createElement("iframe");
            ifr.setAttribute('style',"border: 0px none; margin-left: -20px; height: 850px; margin-top: -150px; width: 800px;");
            ifr.setAttribute('scrolling','no');
            ifr.id = "2embed";
            ifr.src = player_url;
            ifr.allowFullscreen = "true";
            ifr.webkitallowfullscreen="true";
            ifr.mozallowfullscreen="true";
            div.appendChild(ifr);
            location.before(div);
        }
        makecall(process_response);
    }
    else{
        console.log("it's a movie");
        location = document.querySelector('main');
        player_url = "https://www.2embed.ru/embed/imdb/movie?id="+api;
        console.log(player_url);
        let ifr = document.createElement("iframe");
        ifr.setAttribute('style','height:800px; width:100%; margin-left: auto; margin-right: auto;');
        ifr.id = "2embed";
        ifr.allowFullscreen = "true";
        ifr.webkitallowfullscreen="true";
        ifr.mozallowfullscreen="true";
        ifr.src = player_url;

        location.before(ifr);
    }
})();