
How to make AutoPlay work on HEI Network
Hey there everyone. Like many of you, I hate the fact that the AutoPlay feature on the HEI Network is busted. I found a solution and it's pretty easy! I have only tried it on chrome, so YMMV.
- Download the tampermonkey chrome extension. This is what allows you to fix the code under the hood. The link is https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en
- Once installed, click the puzzle piece icon to the right of the url box in chrome, and then click on Tampermonkey. It will open a dialogue box, and you will click "create a new script." You may need to enable the plugin first.
- A new tab will open and you will see a a big, intimidating text box with some code already loaded in it. Select all that code and delete it, starting fresh.
- Copy and paste the following code block into that big text box. Then save it and you are good to go!
- Veg out and watch the Full Cinema playlist back to back to back <3
​
// ==UserScript==
// HEI Network - Fix Playlist Autoplay
// heinetwork.autoplay.fix
// 1.1
// Makes the Autoplay toggle on heinetwork.tv actually advance to the next episode.
// https://www.heinetwork.tv/*
// document-idle
// u/grant none
// ==/UserScript==
(() => {
'use strict';
const KEY = 'hei:autoplay';
const q = (sel, root = document) => root.querySelector(sel);
let armed = false;
function nextUrl(pl) {
let slug = (pl.dataset.nextSlug || '').trim();
if (!slug) {
try {
const list = JSON.parse(pl.dataset.json || '[]');
const i = list.indexOf(pl.dataset.currentSlug);
if (i > -1 && i + 1 < list.length) slug = list[i + 1];
} catch (e) { /* ignore */ }
}
if (!slug) return null;
const path = (pl.dataset.playlistPath || '').replace(/^\/+|\/+$/g, '');
return location.origin + '/' + (path ? path + '/' : '') + slug + '/';
}
function setState(on, host, toggles) {
armed = on;
try { localStorage.setItem(KEY, on ? '1' : '0'); } catch (e) { /* ignore */ }
toggles.forEach(t => { if (t.checked !== on) t.checked = on; });
host.autoplay = false;
try { delete host._nextSlug; } catch (e) { /* ignore */ }
}
function startPlayback(media, wasMuted) {
if (!media || !media.paused) return;
media.play().catch(() => {
media.muted = true;
media.play().then(() => {
const b = q('#unmute-video');
if (b) b.classList.remove('hidden');
}).catch(() => { media.muted = wasMuted; });
});
}
function init() {
const host = q('hei-video');
const pl = q('hei-episode-playlist');
if (!host || !pl) return false;
const controller = host.$controller || q('media-controller', host);
const media = (controller && controller.media) || q('video', host) || host.$video;
const mux = host.$video;
if (!media) return false;
if (host.__heiAutoplayFix) return true;
host.__heiAutoplayFix = true;
const toggles = Array.from(document.querySelectorAll('.autoplay-toggle'));
let saved = false;
try { saved = localStorage.getItem(KEY) === '1'; } catch (e) { /* ignore */ }
setState(saved || toggles.some(t => t.checked), host, toggles);
toggles.forEach(t => ['change', 'click'].forEach(ev =>
t.addEventListener(ev, () => setState(t.checked, host, toggles))
));
let leaving = false;
const onEnded = () => {
if (!armed || leaving) return;
const url = nextUrl(pl);
if (!url) return;
leaving = true;
location.assign(url);
};
media.addEventListener('ended', onEnded);
if (mux && mux !== media) mux.addEventListener('ended', onEnded);
if (armed) {
const wasMuted = media.muted;
if (media.readyState >= 3) startPlayback(media, wasMuted);
else media.addEventListener('canplay', () => startPlayback(media, wasMuted), { once: true });
}
return true;
}
if (!init()) {
const mo = new MutationObserver(() => { if (init()) mo.disconnect(); });
mo.observe(document.documentElement, { childList: true, subtree: true });
setTimeout(() => mo.disconnect(), 20000);
}
})();