HiAnime Auto 1080p

Automatically sets your Quality & Speed to your desired values, Auto Fullscreen, Auto Pause/Unpause when switching tabs, Auto Unmute, Auto Focus.

< Feedback on HiAnime Auto 1080p

Question/comment

§
Posted: 2024-10-17

Refactored and also optionally add match for https://hianime.to/* to change the logo link to redirect to the ACTUAL homepage instead of the random frontpage garbage.


/* global jwplayer */

const desiredQuality = "1080";
const pauseOnFocusLoss = true;
const autoUnmute = false;
const playbackRate = 1;
const autoFullscreen = false;

// Improve logo link
if (location.hostname === 'hianime.to') {
    document.getElementById('logo')?.setAttribute('href', '/home');
}

function waitForElement(selector, callback) {
    const observer = new MutationObserver(() => {
        const element = document.querySelector(selector);
        if (element) {
            observer.disconnect();
            callback(element);
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
}

waitForElement('#megacloud-player', () => {
    const player = jwplayer();
    const qualityMap = { "1080": 1, "720": 2, "360": 3 };

    player.on('firstFrame', () => {
        player.setCurrentQuality(qualityMap[desiredQuality]);
        if (autoUnmute) player.setMute(0);
        if (autoFullscreen) player.setFullscreen(1);
        if (playbackRate !== 1) player.setPlaybackRate(playbackRate);
    });

    if (pauseOnFocusLoss) {
        let wasPlaying = false;
        document.addEventListener("visibilitychange", () => {
            if (document.visibilityState === 'hidden') {
                wasPlaying = player.getState() === 'playing';
                player.pause();
            } else if (wasPlaying) {
                player.play();
            }
        });
    }
});

Post reply

Sign in to post a reply.