Iflix Subtitles Fix for Firefox

Subtitles fix for Firefox

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

// ==UserScript==
// @name         Iflix Subtitles Fix for Firefox
// @namespace    https://github.com/tkhquang
// @version      2.1
// @description  Subtitles fix for Firefox
// @author       Aleks
// @license      MIT; https://raw.githubusercontent.com/tkhquang/userscripts/master/LICENSE
// @homepage     https://gf.qytechs.cn/en/scripts/367324-iflix-subtitles-fix-for-firefox
// @match        http*://piay.iflix.com/*
// @run-at       document-start
// @require      https://gf.qytechs.cn/scripts/21927-arrive-js/code/arrivejs.js
// @grant        GM_addStyle
// @noframes
// ==/UserScript==

/*
 * arrive.js
 * v2.4.1
 * https://github.com/uzairfarooq/arrive
 * MIT licensed
 *
 * Copyright (c) 2014-2017 Uzair Farooq
 */

/*==================*
 * Reference: http://ronallo.com/demos/webvtt-cue-settings/
 * You can change the below variables to suite your needs.
 *==================*/

// ==Configuration==
const lineVTT = 14; //See reference
const minfontSize = "12px"; //Subtitles font-size won't scale smaller than this value
const fontSize = "3vmin"; //font-size = minfontSize + this value
const lineHeight = "150%"; //Better leave this as is - "normal" with lineVTT = 16
// ==Configuration==

//Codes
function styleSub() {
    "use strict";

    if (!(/^\/play/).test(window.location.pathname)) {
        return;
    }
    const css = `video::cue {
font-size: calc(${minfontSize} + ${fontSize}) !important;
line-height: ${lineHeight} !important;
}`;
    if (typeof GM_addStyle !== "undefined") {
        GM_addStyle(css);
    } else {
        const node = document.createElement("style");
        node.type = "text/css";
        node.appendChild(document.createTextNode(css));
        const heads = document.getElementsByTagName("head");
        if (heads.length > 0) {
            heads[0].appendChild(node);
        } else {
            document.documentElement.appendChild(node);
        }
    }
    console.log("iSFix - Styling Done!");
}

function alterSub(activeSub) {
    "use strict";

    let activeCues = activeSub.cues;
    function lineCheck() {
        return Boolean(activeCues !== null &&activeCues[0] !== undefined &&
                       activeCues[0].line === lineVTT);
    }
    if (activeCues !==null && activeCues[0].line !== lineVTT) {
        Object.keys(activeCues).forEach(function (i) {
            activeCues[i].line = lineVTT;
        });
        console.log("iSFix - Done setting lines!");
    }
    if (!lineCheck()) {
        console.log("iSFix - Current line value: " + activeCues[0].line);
        console.warn("iSFix - Unmodified lines => Try changing line value...");
        setTimeout(function () {
            alterSub(activeSub);
        }, 5000);
        return;
    }
    console.log("iSFix - Current line value: " + activeCues[0].line);
    console.log("iSFix - Passed!!!");
}

function getSubList(vidPlayer) {
    "use strict";

    const subList = vidPlayer[0].textTracks;
    function getSub() {
        return (function () {
            for (let sub of subList) {
                if (sub.mode === "showing") {
                    return sub;
                }
            }
            return false;
        }());
    }
    subList.onchange = function() {
        console.log("iSFix - Subtitles onchange action");
        if (getSub()) {
            alterSub(getSub());
        }
    };
    setTimeout(function() {
        if (getSub()) {
            alterSub(getSub());
        }
    }, 10000);
}

function getVidState(vidPlayer, timer) {
    "use strict";

    if ((timer === true && vidPlayer.length === 0) || vidPlayer[0] === undefined) {
        console.warn("iSFix - No video? Try getting it after 5s...");
        timer = setTimeout(function () {
            getVidState(vidPlayer, true);
        }, 5000);
        return;
    }
    clearTimeout(timer);
    styleSub();
    getSubList(vidPlayer);
}

(function() {
    "use strict";

    document.arrive(".vimond-player-video", function() {
        console.log("iSFix - Video element available");
        setTimeout(getVidState(document.getElementsByClassName("vimond-player-video"),true), 1000);
    });
    document.leave(".vimond-player-video", function() {
        console.log("iSFix - Video element unavailable");
        getVidState(document.getElementsByClassName("vimond-player-video"),false);
    });
}());

QingJ © 2025

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