Plex- Add IMDB Link

Add an IMDB Link to Plex

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name  Plex- Add IMDB Link
// @description Add an IMDB Link to Plex
// @match http://virgulestar.noip.me:32400/*
// @grant GM_xmlhttpRequest
// @version 0.0.2.20220211
// @namespace https://greasyfork.org/users/718390
// @license MIT
// ==/UserScript==

'use strict';

//since plex is a spa (single page app), we have to perpetually monitor the page elements that get rendered, we can't count on a traditional full browser page refresh
var timerHandle = setInterval(main, 1000);

function main() {

    //"metadata" string in url means we're on an actual movie page in plex, otherwise just keep looping on timer
    if (window.location.href.indexOf("metadata") === -1) return;

    //also keep looping till we see the title element get rendered
    var titleElement = document.querySelector("div[data-testid='preplay-mainTitle']");
    if (!titleElement) return;
    var title = titleElement.textContent;
    var year = document.querySelector("div[data-testid='preplay-secondTitle']").textContent;

    //now that we've found a title we can do our bizness...
    //but only if we haven't already =)
    if (document.getElementById("imdbLink")) {
        clearInterval(timerHandle);
        return;
    }

    var imdbLinkQueryUrl = "https://v2.sg.media-imdb.com/suggestion/" + title[0].toLowerCase() + "/" + encodeURI(title + " (" + year +")") + ".json";
    console.log("imdb query:" + imdbLinkQueryUrl);

    //stack-o showed this oddball imdb "api" we can use to look up the magic imdb "id" for a movie
    //https://stackoverflow.com/questions/1966503/does-imdb-provide-an-api/7744369#7744369
    GM_xmlhttpRequest({
        method: "GET",
        url: imdbLinkQueryUrl,
        onload: function (response) {

            //wrapper existing imdb rating with a link to the imdb url for the movie
            var imdbLink = document.createElement("a");
            imdbLink.id = "imdbLink";
            var imdbRatingElement = document.querySelector("div[title^='IMDb Rating']");
            imdbRatingElement.parentNode.insertBefore(imdbLink, imdbRatingElement);
            imdbLink.appendChild(imdbRatingElement);

            if (response.responseText.indexOf("Bad query") > -1) {
                imdbLink.appendChild("not found on imdb");
            }
            else {
                var getId = /\"id\":\"(.*?)\"/;
                var match = response.responseText.match(getId); //match[1] will contain the id for the win!

                //finally we get to jam in our href to the corresponding imdb movie deets page!
                //nugget: cool part here is we can target the anchor id for the user reviews!! if that's not your main interest, just remove
                imdbLink.href = "https://www.imdb.com/title/" + match[1] + "/#titleUserReviewsTeaser";
                imdbLink.target = "_blank";
            };
        }
    });
}