Giter Club home page Giter Club logo

Comments (2)

radityaharya avatar radityaharya commented on June 16, 2024

Hi, I haven't used Jellyfin for a while, but you could probably fork the repo and change the following lines:

...
async function homePageScripts() {
    console.log("CUSTOM: home page scripts");
    let latestShows = await JellyfinApi('/Users/' + userId + '/Items/Latest?Limit=10&Recursive=true&IncludeItemTypes=Series&Fields=Id', 'GET');
    let series = [];
    for (let i = 0; i < latestShows.length; i++) {
        let show = await JellyfinApi('/Users/' + userId + '/Items/' + latestShows[i]["Id"] + '?&Fields=Id%2CName%2COverview%2CImageTags', 'GET');
        await series.push(show);
    }
...

Change the latestShows values to an array of item ids(Movies or series) and change the latestShows[i]["Id"] accordingly.

To use it. follow the instruction as usual but change the script source to https://raw.githubusercontent.com/`your github username`/custom-tweaks/main/jellyfin/custom.js

from custom-tweaks.

jakitamkolwiek avatar jakitamkolwiek commented on June 16, 2024

Hi, I could only sit down to this now, your code works :) but I managed to get to this stage. What I was more interested in was for Hero to show pre-selected movies from the already built jellyfin library. I spent some time with ChatGPT and came up with this code:

`var credentials = JSON.parse(localStorage.getItem('jellyfin_credentials'));
var apiKey = 'APIKEY'; // Twój klucz API
var userId = credentials["Servers"][0]["UserId"];
var deviceId = Object.keys(localStorage).filter(function (key) { return key.indexOf("deviceId") > -1; })[0];
deviceId = localStorage.getItem(deviceId);
var server = window.location.origin;
var heroHasRun = false;

function pageLocation() {
var locations = {
"home": "/web/index.html#!/home.html",
"movies": "/web/index.html#!/movies.html",
"tvshows": "/web/index.html#!/tv.html",
"music": "/web/index.html#!/music.html",
"details": "/web/index.html#!/details",
"queue": "/web/index.html#!/queue"
};
var location = window.location.href;
var page = "home";
for (var key in locations) {
if (location.indexOf(locations[key]) > -1) {
page = key;
}
}
return page;
}

function isMobile() {
return window.innerWidth < 800;
}

if (!isMobile()) {
var selectedMovieIds = ["ID1", "ID2", "ID3", "ID4", "Id5", "ID6"];

async function fetchMovieDetails(movieId) {
    try {
        var response = await fetch(server + '/Users/' + userId + '/Items/' + movieId + '?Fields=Id%2CName%2COverview%2CImageTags', {
            method: 'GET',
            headers: {
                'X-Emby-Token': apiKey // Użyj klucza API w nagłówku
            }
        });
        if (response.ok) {
            var movie = await response.json();
            return movie;
        }
    } catch (error) {
        console.error(error);
    }
    return null;
}

async function customMovieList() {
    try {
        var movies = [];
        for (var i = 0; i < selectedMovieIds.length; i++) {
            var movie = await fetchMovieDetails(selectedMovieIds[i]);
            if (movie) {
                movies.push(movie);
            }
        }

        if (heroHasRun || document.querySelectorAll('#indexPage:not(.hide) .heroContainer').length > 0) {
            return;
        }

        addHero();

        var i = 0;
        while (true) {
            var heroTitle = document.querySelector("#indexPage:not(.hide) .heroTitle");
            var heroDescription = document.querySelector("#indexPage:not(.hide) .heroDescription");
            var heroButton = document.querySelector("#indexPage:not(.hide) .heroButton");
            var heroLogoImage = document.querySelector("#indexPage:not(.hide) .heroLogoImage");

            heroTitle.innerHTML = movies[i]["Name"];
            document.querySelector("#indexPage:not(.hide) .heroLogo").classList.remove("hide");
            heroTitle.classList.remove("noLogo");
            heroDescription.innerHTML = movies[i]["Overview"];

            heroButton.onclick = function () {
                var url = "/web/index.html#!/details?id=" + movies[i]["Id"];
                window.history.state.url = url;
                window.history.pushState(window.history.state, "", url);
                window.history.go(0);
            };

            var heroBackgroundContainer = document.querySelector("#indexPage:not(.hide) .heroBackgroundContainer");
            heroBackgroundContainer.innerHTML = '';

            for (var j = 0; j < movies.length; j++) {
                var temp = document.createElement("img");
                temp.className = "heroBackground hide";
                temp.src = server + "/Items/" + movies[j]["Id"] + "/Images/Backdrop?maxWidth=1920&tag=" + movies[j]["ImageTags"]["Backdrop"] + "&quality=50";
                temp.id = movies[j]["BackdropImageTags"];
                heroBackgroundContainer.appendChild(temp);
            }

            document.querySelectorAll(".heroBackground").forEach(function (element) {
                element.classList.add("hide");
            });

            document.querySelectorAll("[id='" + movies[i]["BackdropImageTags"] + "']").forEach(function (element) {
                element.classList.remove("hide");
            });

            await new Promise(r => setTimeout(r, 5000));
            i = (i + 1) % movies.length;
        }
    } catch (error) {
        console.error(error);
    }
}

if (pageLocation() == "home") {
    customMovieList();
}

} else {
console.log("To jest telefon lub tablet. Kod JavaScript nie zostanie uruchomiony na tych urządzeniach.");
}
`

Unfortunately, nothing is displayed ;( but the idea remains :)

Oh, and I'll say it again, great job!

from custom-tweaks.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.