Guest User

Untitled

a guest
Sep 13th, 2024
2,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         IMDB Movie or TV Show
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2024-09-13
  5. // @description  Adds an embedded video for streaming on any IMDB movie or TV show page with multiple mirrors.
  6. // @author       FlinCode
  7. // @match        https://www.imdb.com/title/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=imdb.com
  9. // @grant        none
  10. // @license MIT
  11. // @downloadURL  https://update.greasyfork.org/scripts/508237/IMDB%20Movie.user.js
  12. // @updateURL    https://update.greasyfork.org/scripts/508237/IMDB%20Movie.meta.js
  13. // ==/UserScript==
  14.  
  15. (function() {
  16.     'use strict';
  17.  
  18.     function getIframe(url) {
  19.         const iframe = document.createElement('iframe');
  20.         iframe.src = url;
  21.         iframe.width = '100%';
  22.         iframe.height = '600';
  23.         iframe.frameBorder = '0';
  24.         iframe.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
  25.         iframe.allowFullscreen = true;
  26.         return iframe;
  27.     }
  28.  
  29.     const currentUrl = window.location.href;
  30.     const idMatch = currentUrl.match(/title\/(tt\d+)\//);
  31.     const imdbId = idMatch ? idMatch[1] : null;
  32.  
  33.     if (!imdbId) { return }
  34.  
  35.     // Fetch the meta property "og:type" to check if it's a movie or a TV show
  36.     const ogTypeMeta = document.querySelector('meta[property="og:type"]');
  37.     const ogType = ogTypeMeta ? ogTypeMeta.getAttribute('content') : null;
  38.  
  39.     if (!ogType) { return }
  40.  
  41.     let embedUrl = '';
  42.  
  43.     // Determine if it's a movie or TV show based on the og:type content
  44.     if (ogType === 'video.movie') {
  45.         embedUrl = `https://2embed.in/movie/${imdbId}`;
  46.     } else if (ogType === 'video.tv_show') {
  47.         embedUrl = `https://2embed.in/tv/${imdbId}`;
  48.     }
  49.  
  50.     if (embedUrl) {
  51.         const result = document.evaluate(
  52.             '//*[@id="__next"]/main/div/section[1]/section/div[3]/section/section/div[2]',
  53.             document,
  54.             null,
  55.             XPathResult.FIRST_ORDERED_NODE_TYPE,
  56.             null
  57.         );
  58.  
  59.         const topDiv = result.singleNodeValue;
  60.         if (topDiv) {
  61.             const iframe = getIframe(embedUrl);
  62.             topDiv.insertAdjacentElement("afterend", iframe);
  63.         }
  64.     }
  65. })();
  66.  
Advertisement
Add Comment
Please, Sign In to add comment