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

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         IMDB Video Player - 2embed (play streaming videos from IMDb)
// @name:fr      Lecture en Streaming de films et séries IMDb
// @namespace    https://greasyfork.org/fr/scripts/437200-imdb-video-player-2embed-play-streaming-videos-from-imdb
// @version      0.3
// @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://m.media-amazon.com/images/G/01/imdb/images-ANDW73HA/favicon_desktop_32x32._CB1582158068_.png
// @grant        GM_xmlhttpRequest
// @connect      imdb.com
// @connect      2embed.ru
// @connect      api.themoviedb.org
// ==/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')) {
        getTmdbIDSerie()
        .then(insertPlayerSerie)
        .catch(e => console.log(e.message));
        
    } else {
        insertPlayerMovie();   
    }

    function getTmdbIDSerie(){
        return new Promise((resolve,reject)=>{
            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);
                        resolve(tmdb_id);
                }
            });
        });
    }

    function insertPlayerSerie(tmdb_id){
        return new Promise((resolve,reject)=>{
            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);
            resolve();
        });
    }

    function insertPlayerMovie(){
            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);
    }
})();