Iflix Subtitles Fix for Firefox 59

Subtitles fix for Firefox

目前為 2018-05-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Iflix Subtitles Fix for Firefox 59
// @namespace    https://github.com/tkhquang
// @version      1.2
// @description  Subtitles fix for Firefox
// @author       Aleks
// @include      *://piay.iflix.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

document.addEventListener("DOMContentLoaded", obserEvt, false);
if (document.readyState === "complete") {
    obserEvt();
}

function obserEvt() {
    console.log("iflix Subtitles Fix - Observation started");
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList') {
                for (let i = 0; i < mutation.addedNodes.length; i++) {
                    if (mutation.addedNodes[i].nodeName === 'VIDEO') {
                        console.log('iflix Subtitles Fix - Video element available');
                        styleF();
                        getVideo();
                    }
                }
            }
            for (let i = 0; i < mutation.removedNodes.length; i++) {
                if (mutation.removedNodes[i].nodeName === 'video') {
                    console.log('iflix Subtitles Fix - Video element removed');
                }
            }
        });
    });

    observer.observe(document, {
        childList: true,
        attributes: false,
        characterData: false,
        subtree: true
    });

    var getVideo = function getVideo() {
        var vimond = document.getElementsByTagName('video')[0];
        if (vimond == undefined) {
            return;
        }
        vimond.onplaying = function() {
            console.log("iflix Subtitles Fix - The video is now playing");
        };
        var vimondSubList = vimond.textTracks;
        vimondSubList.onchange = function() {
            console.log("iflix Subtitles Fix - Subtitles function");
            alterSub();
            lineCheck();
        };
    };

    var alterSub = function alterSub() {
        setTimeout(function() {
            var vimond = document.getElementsByTagName('video')[0];
            if (vimond == undefined) {
                return;
            }
            var vimondSubList = vimond.textTracks;
            for (let i = 0; i < vimondSubList.length; i++) {
                if (vimondSubList[i].mode === 'showing') {
                    var selectedSub = vimondSubList[i];
                    for (let i = 0; i < selectedSub.cues.length; i++) {
                        selectedSub.cues[i].line = 14;
                    }
                    console.log("iflix Subtitles Fix - Done!");
                }
            }
        }, 500);
    };

    var lineCheck = function lineCheck() {
        setTimeout(function() {
            var vimond = document.getElementsByTagName('video')[0];
            if (vimond == undefined) {
                return;
            }
            var vimondSubList = vimond.textTracks;
            for (let i = 0; i < vimondSubList.length; i++) {
                if (vimondSubList[i].mode === 'showing') {
                    var selectedSub = vimondSubList[i];
                    var CurLineValue = selectedSub.cues[0].line;
                    //if (selectedSub.cues.length == 0) {
                    //   console.log("No Subtitle");
                    //}
                    console.log("iflix Subtitles Fix - Current Line Value: " + CurLineValue);

                    if (CurLineValue !== 14) {
                        console.log("iflix Subtitles Fix - Error! Unmodified Lines - Alter Again");
                        alterSub();
                    } else console.log("iflix Subtitles Fix - All Good!!!");
                }
            }
        }, 5000);
    };

    var styleF = function styleF() {
        var css = "";
        if (false || (document.location.href.indexOf("https://piay.iflix.com/play/") == 0) || (document.location.href.indexOf("http://piay.iflix.com/play/*") == 0))
            css += [
                "::cue {",
                "    font-size: 32px !important;",
                "    padding: 3px !important;",
                "    line-height: 1.5 !important;",
                "}"
            ].join("\n");
        if (typeof GM_addStyle != "undefined") {
            GM_addStyle(css);
        } else if (typeof PRO_addStyle != "undefined") {
            PRO_addStyle(css);
        } else if (typeof addStyle != "undefined") {
            addStyle(css);
        } else {
            var node = document.createElement("style");
            node.type = "text/css";
            node.appendChild(document.createTextNode(css));
            var heads = document.getElementsByTagName("head");
            if (heads.length > 0) {
                heads[0].appendChild(node);
            } else {
                // no head yet, stick it whereever
                document.documentElement.appendChild(node);
            }
        }
        console.log("Styling Done!");
    };
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址