burning series enhancer

Wechselt automatisch zum Vivo- oder Vupload-Tab auf burning series und öffnet Vivo oder Vupload. Das Tool startet das nächste Video und falls nötig die nächste Staffel, wenn eine Episode beendet wurde. Burning series enhancer bietet eine Downloadfunktion.

Versión del día 27/01/2022. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @icon           https://bs.to/favicon.ico
// @name           burning series enhancer
// @name:en        burning series enhancer
// @author         xtrars
// @description    Wechselt automatisch zum Vivo- oder Vupload-Tab auf burning series und öffnet Vivo oder Vupload. Das Tool startet das nächste Video und falls nötig die nächste Staffel, wenn eine Episode beendet wurde. Burning series enhancer bietet eine Downloadfunktion.
// @description:en Automatically switches to the Vivo or Vupload tab on burning series and opens Vivo or Vupload. The tool starts the next video and if necessary the next season when an episode is finished. Burning series enhancer provides a download function.
// @version        7.1
// @run-at         document-body
// @license        GPL-3.0-or-later
// @namespace      https://greasyforks.org/users/140785

// @grant          GM_setValue
// @grant          GM_getValue
// @grant          GM_addValueChangeListener
// @grant          GM_removeValueChangeListener
// @grant          GM_download
// @grant          GM_info
// @grant          GM_addStyle
// @grant          GM_getResourceText
// @grant          window.close
// @grant          window.focus

// @include        https://bs.to/*
// @include        https://burningseries.co/*
// @include        https://burningseries.sx/*
// @include        https://burningseries.vc/*
// @include        https://burningseries.ac/*
// @include        https://burningseries.cx/*
// @include        https://burningseries.nz/*
// @include        https://burningseries.se/*

// @include        https://vivo.sx/*
// @include        https://vivo.st/*
// @include        https://vupload.com/*
// @include        https://*.vivo.sx/*
// @include        https://*.vivo.st/*
// @include        https://*.megaupload.to/*
// @include        https://voe.sx/*

// @require        https://unpkg.com/hls.js@latest/dist/hls.js
// @require        https://unpkg.com/video.js@latest/dist/video.min.js

// ==/UserScript==

class BaseHandler {
    waitForElement(sSelector, bWaitUnlimited = true) {
        return new Promise(async resolve => {
            if (document.querySelector(sSelector)) {
                return resolve(document.querySelector(sSelector));

            }

            const observer = new MutationObserver(() => {
                if (document.querySelector(sSelector)) {
                    resolve(document.querySelector(sSelector));
                    observer.disconnect();
                }
            });

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

            if (!bWaitUnlimited) {
                setTimeout(() => {
                    resolve(document.querySelector(sSelector));
                    observer.disconnect();
                }, 3000);
            }
        });
    }

    hasUrl(aSelector) {
        let isAvailable = true;
        for (let selector of aSelector) {
            isAvailable = document['location']['href'].search(selector) !== -1;
            if (!isAvailable) {
                return false;
            }
        }
        return true;
    }

    reload(iDelay = 300) {
        setTimeout(() => {
            window.location.reload();
        }, iDelay);
    }

    querySelectorAllRegex(sSelector = '*', sAttribute = 'name', rRegex = /.*/) {
        for (const eElement of document.querySelectorAll(sSelector)) {
            if (rRegex.test(eElement[sAttribute])) {
                return true;
            }
        }
        return false;
    }
}

class BurningSeriesHandler extends BaseHandler {
    initGMVariables() {
        if (typeof GM_getValue('bActivateEnhancer') === "undefined") {
            GM_setValue('bActivateEnhancer', false);
        }

        if (typeof GM_getValue('bAutoplayNextEpisode') === "undefined") {
            GM_setValue('bAutoplayNextEpisode', true);
        }
        if (typeof GM_getValue('bAutoplayVideo') === "undefined") {
            GM_setValue('bAutoplayVideo', true);
        }
        if (typeof GM_getValue('bAutoplayNextSeason') === "undefined") {
            GM_setValue('bAutoplayNextSeason', true);
        }
        if (typeof GM_getValue('bAutoplayRandomEpisode') === "undefined") {
            GM_setValue('bAutoplayRandomEpisode', false);
        }
        if (typeof GM_getValue('bDownloadVideo') === "undefined") {
            GM_setValue('bDownloadVideo', false);
        }
        if (typeof GM_getValue('bExtraSettings') === "undefined") {
            GM_setValue('bExtraSettings', false);
        }
        if (typeof GM_getValue('bDownloadType') === "undefined") {
            GM_setValue('bDownloadType', true);
        }
        if (typeof GM_getValue('bFirstStart') === "undefined") {
            GM_setValue('bDownloadType', true);
        }
        if (typeof GM_getValue('bSelectHoster') === "undefined") {
            GM_setValue('bSelectHoster', 'voe');
        }
        if (typeof GM_getValue('bSkipEnd') === "undefined") {
            GM_setValue('bSkipEnd', false);
        }
        if (typeof GM_getValue('bSkipEndTime') === "undefined") {
            GM_setValue('bSkipEndTime', 0);
        }
    }

    hasAnotherHoster() {
        return this.hasUrl([/^https:\/\/(bs.to|burningseries.[a-z]{2,3})\/.*[0-9]{1,2}\/[0-9]{1,2}-.*\/[a-z]+\/(?!Vivo|Vupload|VOE).*/g]);
    }

    isEpisode() {
        return this.hasUrl([/^https:\/\/(bs.to|burningseries.[a-z]{2,3})/g, /[0-9]{1,2}\/[0-9]{1,2}-/g]);
    }

    async clickPlay() {
        return new Promise(async resolve => {
            let playerElem = await this.waitForElement('section.serie .hoster-player').catch(() => {
            });
            let iNumberOfClicks = 0;
            let clickInterval = setInterval(async () => {
                if (playerElem) {
                    if (document.querySelector('section.serie .hoster-player > a') ||
                        document.querySelector('section.serie .hoster-player > iframe') ||
                        iNumberOfClicks > 120 ||
                        this.querySelectorAllRegex('iframe', 'title', /recaptcha challenge/)) {
                        clearInterval(clickInterval);
                        resolve();
                    }
                    iNumberOfClicks++;
                    let clickEvent = new Event('click');
                    clickEvent.which = 1;
                    clickEvent.pageX = 6;
                    clickEvent.pageY = 1;
                    playerElem.dispatchEvent(clickEvent);
                }
            }, 500);
        });
    }

    playNextEpisodeIfVideoEnded(bSetEvent = true) {
        if (!bSetEvent) {
            GM_removeValueChangeListener('isLocalVideoEnded');
            return;
        }
        GM_addValueChangeListener('isLocalVideoEnded', () => {
            if (GM_getValue('isLocalVideoEnded')) {
                GM_setValue('isLocalVideoEnded', false);
                window.focus();
                if (GM_getValue('bAutoplayRandomEpisode')) {
                    let oRandomEpisode = document.querySelector('#sp_right > a');
                    document['location'].replace(oRandomEpisode.href);
                }
                else {
                    let oNextEpisode = document.querySelector('.serie .frame ul li[class^="e"].active ~ li:not(.disabled) a');
                    if (oNextEpisode) {
                        document['location'].replace(oNextEpisode.href);
                    }
                    else if (GM_getValue('bAutoplayNextSeason')) {
                        let oNextSeason = document.querySelector('.serie .frame ul li[class^="s"].active ~ li:not(.disabled) a');
                        if (oNextSeason) {
                            GM_setValue('clickFirstSeason', true);
                            document.location.replace(oNextSeason);
                        }
                    }
                }
            }
        });
    }

    appendOwnStyle() {
        const style = document.createElement('style');
        style.innerHTML = `
              :root {
              --inner-pl: 14px;
              --inner-bc-before: #2FB536;
              --inner-bc-after: #12A6F6;
              --color: white;
            }
            
            button.tab {
                background-color: transparent;
                color: white;
                float: left;
                border: none;
                outline: none;
                cursor: pointer;
                padding: 10px;
                padding-top: 7px;
                user-select: none;
            }
            
            @keyframes shake {
                10%, 90% {transform: translate3d(-.5px, 0, 0);}
                20%, 80% {transform: translate3d(1px, 0, 0);}
                30%, 50%, 70% {transform: translate3d(-2px, 0, 0);}
                40%, 60% {transform: translate3d(2px, 0, 0);}
            }
            .onoffswitch {
                z-index: 161;
                position: relative; width: 100%;
            }

            .onoffswitch-label {
                width: calc(100% - 20px);
                display: block;
                overflow: hidden;
                float: left;
            }
            .onoffswitch-inner {
                display: inline-block; width: 200%; margin-left: -100%;
                transition: margin 0.3s ease-in 0s;
            }
                        
            .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
                margin-left: 0;
            }
            
            .onoffswitch-checkbox.disabled {
                pointer-events: none;
                -webkit-user-select: none; /* Safari */
                user-select: none; /* Standard syntax */
            }
                        
            .onoffswitch-inner:before, .onoffswitch-inner:after {
                display: block; 
                float: left; 
                width: 50%; 
                padding-left: 10px;
                font-size: 10px; 
                font-family: Trebuchet, Arial, sans-serif;
                box-sizing: border-box;
            }
            
            #xtrars-btn {
               float: right;
               background: #12a6f6;
               border-radius: 50%;
               width: 70px;
               height: 70px;
               line-height: 81px;
               text-align: center;
               cursor: pointer;
               animation: shake 1s ease 1s 1 normal;
            }
            
            #xtrars-menu {
               right: 4;
            }
            
            #xtrars-btn-icon {
               color: var(--color);
            }
            
            .onoffswitch-checkbox {
                float: left;
                margin-top: 3px;
                cursor: pointer;
            }
            
            .onoffswitch.disabled { 
                color: grey;            
            }
            
            .xtrars-switch {
                position: relative;
                display: inline-block;
                width: 30px;
                height: 17px;
                margin-top: 6px;
                margin-left: 10px;
            }
            
            .xtrars-switch input { 
                opacity: 0;
                width: 0;
                height: 0;
            }
            
            .xtrars-slider {
                position: absolute;
                cursor: pointer;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background-color: #ccc;
                -webkit-transition: .4s;
                transition: .4s;
            }
            
            .xtrars-slider:before {
                position: absolute;
                content: "";
                height: 13px;
                width: 15px;
                left: 2px;
                bottom: 2px;
                background-color: white;
                -webkit-transition: .4s;
                transition: .4s;
            }
            
            input:checked + .xtrars-slider {
                background-color: #669900;
            }
            
            input:focus + .xtrars-slider {
                box-shadow: 0 0 1px #669900;
            }
            
            input:checked + .xtrars-slider:before {
                -webkit-transform: translateX(11px);
                transform: translateX(11px);
            }
            
            .onoffswitch-inner.autoplay:before {
                content: "Video-Autoplay aktiviert";
            }
            .onoffswitch-inner.autoplay:after {
                content: "Video-Autoplay deaktiviert";
            }
            .onoffswitch-inner.auto-next-episode:before {
                content: "Nächste Episode wird automatisch abgespielt";
            }
            .onoffswitch-inner.auto-next-episode:after {
                content: "Nächste Episode wird manuell abgespielt";
            }
            .onoffswitch-inner.enable-enhancer:before {
                content: "burning series enhancer aktiviert";
            }
            .onoffswitch-inner.enable-enhancer:after {
                content: "burning series enhancer deaktiviert";
            }
            .onoffswitch-inner.auto-next-season:before {
                content: "Nächste Staffel wird automatisch abgespielt";
            }
            .onoffswitch-inner.auto-next-season:after {
                content: "Nächste Staffel wird manuell abgespielt";
            }
            .onoffswitch-inner.auto-random-episode:before {
                content: "Nächste folgende Episode wird abgespielt";
            }
            .onoffswitch-inner.auto-random-episode:after {
                content: "Nächste Episode wird zufällig abgespielt";
            }
            .onoffswitch-inner.download:before {
                content: "Downloadfunktion aktiviert";
            }
            .onoffswitch-inner.download:after {
                content: "Downloadfunktion deaktiviert";
            }
            .onoffswitch-inner.download-type:before {
                content: "Video wird heruntergeladen & Stream angeschaut";
            }
            .onoffswitch-inner.download-type:after {
                content: "Video wird heruntergeladen & Stream geschlossen";
            }                    
            
            .onoffswitch-inner.skip-end:before {
                content: "Video wird x Sekunden vor Ende beendet";
            }
            .onoffswitch-inner.skip-end:after {
                content: "Video spielt bis zum Ende";
            }
            .disabled:after {
                background-color: darkgrey !important;
            }
            .disabled:before {
                background-color: darkgrey !important;
            }
            .hidden {
                visibility: hidden !important;
            }
            
            .xtrars-tabcontent::-webkit-scrollbar {
                width: 10px;
            }
            
            .xtrars-tabcontent::-webkit-scrollbar-track {
                background: #fdfdfd; 
            }
             
            .xtrars-tabcontent::-webkit-scrollbar-thumb {
                background: #12a6f6; 
            }
            
            .xtrars-tabcontent::-webkit-scrollbar-thumb:hover {
                background: #0296d6; 
            }
            
            .xtrars-tabcontent {
                display: none;
                padding: 10px;
                width: 100%;
                height: calc(100% - 60px);
                overflow: auto;
            }
            
            .xtrars-active {
                text-shadow: -0.3px 0 #12a6f6, 0.3px 0 #12a6f6 !important; 
                color: #12a6f6 !important; 
                background-color: rgb(253, 253, 253) !important;
            }
            
            #xtrars-settings-toolbar {
                height: 30px; 
                width: 100%; 
                background-color: #12a6f6; 
                color: white; 
                line-height: 30px;
            }
            
            .xtrars-toolbar-text {
                display: inline-block; 
                margin-left: 10px; 
                user-select: none; 
                width: calc(100% - 125px); 
                text-overflow: ellipsis; 
                overflow: hidden; 
                white-space: nowrap;
            }
            .xtrars-select {
                display: inline; 
                font-size: 10px; 
                padding: 0 8px; 
                border-radius: 0;
                outline: none;
            }
            
            /*Thanks to Aaron Iker https://codepen.io/aaroniker/pen/XyXzYp*/
            .xtrars-search {
                display: inline-table;
                float: right;
                margin-right: 10px;
            }
            .xtrars-search input {
                box-shadow: none;
                border-radius: 0;
                -moz-border-radius: 0;
                -webkit-border-radius: 0;
                background: none;
                border: none;
                outline: none;
                width: 14px;
                min-width: 0;
                padding: 0;
                z-index: 1;
                position: relative;
                line-height: 10px;
                margin: 8px 0;
                font-size: 12px;
                -webkit-appearance: none;
                transition: all 0.6s ease;
                cursor: pointer;
                color: #fff;
            }
            .xtrars-search input + div {
                position: relative;
                height: 14px;
                width: 100%;
                margin: -21px 0 0 0;
            }
            .xtrars-search input + div svg {
                display: block;
                position: absolute;
                height: 14px;
                width: 79px;
                right: 0;
                top: 0;
                fill: none;
                stroke: #fff;
                stroke-width: 1.5px;
                stroke-dashoffset: 271.908;
                stroke-dasharray: 59 212.908;
                transition: all 0.6s ease;
            }
            .xtrars-search input:not(:-moz-placeholder-shown) {
                width: 80px;
                padding: 0 4px;
                cursor: text;
            }
            .xtrars-search input:not(:-ms-input-placeholder) {
                width: 80px;
                padding: 0 4px;
                cursor: text;
            }
            .xtrars-search input:not(:placeholder-shown), .xtrars-search input:focus {
                width: 80px;
                padding: 0 4px;
                cursor: text;
            }
            .xtrars-search input:not(:-moz-placeholder-shown) + div svg {
                stroke-dasharray: 150 212.908;
                stroke-dashoffset: 300;
            }
            .xtrars-search input:not(:-ms-input-placeholder) + div svg {
                stroke-dasharray: 150 212.908;
                stroke-dashoffset: 300;
            }
            .xtrars-search input:not(:placeholder-shown) + div svg, .xtrars-search input:focus + div svg {
                stroke-dasharray: 150 212.908;
                stroke-dashoffset: 300;
            }`;
        document.head.appendChild(style);
    }

    async buildButton() {
        const button = document.createElement("div");
        button.id = 'xtrars-btn';
        button.innerHTML = '<i id="xtrars-btn-icon" class="fas fa-cogs fa-2x"></i>';
        await this.waitForElement('.infos').catch(() => {
        });
        document.getElementsByClassName('infos')[0].insertBefore(button,
            document.getElementsByClassName('infos')[0].firstChild);
    }

    buildSettingsWindow() {
        const settingsWindow = document.createElement("div");
        settingsWindow.innerHTML = `
            <div id="xtrars-settings-toolbar">
                <div class="xtrars-toolbar-text">burning series enhancer - Settings</div>
                <button id="xtrars-settings-close-btn" style="user-select: none; float: right; margin-top: 6px; background-color: transparent; border: none; 
                margin-right: 10px; cursor: pointer; font-weight: bolder; color: white;" onclick="closeSettingsWindow">✕</button>
                
                <div class="xtrars-search">
                    <input class="xtrars-search-input" type="text" placeholder=" ">
                <div>
                        <svg>
                            <use xlink:href="#path">
                        </svg>
                    </div>
                </div>
                    
                <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                    <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 28" id="path">
                        <path d="M32.9418651,-20.6880772 C37.9418651,-20.6880772 40.9418651,-16.6880772 40.9418651,-12.6880772 C40.9418651,-8.68807717 37.9418651,-4.68807717 32.9418651,-4.68807717 C27.9418651,-4.68807717 24.9418651,-8.68807717 24.9418651,-12.6880772 C24.9418651,-16.6880772 27.9418651,-20.6880772 32.9418651,-20.6880772 L32.9418651,-29.870624 C32.9418651,-30.3676803 33.3448089,-30.770624 33.8418651,-30.770624 C34.08056,-30.770624 34.3094785,-30.6758029 34.4782612,-30.5070201 L141.371843,76.386562" transform="translate(83.156854, 22.171573) rotate(-225.000000) translate(-83.156854, -22.171573)"></path>
                    </symbol>
                </svg>            
            </div>
            <div id="xtrars-settings-tabs" 
            style="height: 30px; width: 100%; background-color: #12a6f6; color: white; line-height: 30px">
                <button class="tab xtrars-settings-tabs xtrars-active" data-tab="BS">BS</button>
                <button class="tab xtrars-settings-tabs" data-tab="Streaming">Streaming</button>
                <button class="tab xtrars-settings-tabs" data-tab="Download">Download</button>
                <button class="tab xtrars-settings-tabs" data-tab="Info">Info</button>
                
                <label class="xtrars-switch">
                    <input type="checkbox" class="xtrars-onoffswitch">
                    <span class="xtrars-slider"></span>
                </label>
            </div>
            <!-- Tab content -->
            <div id="BS" class="xtrars-tabcontent" style="display: block; overflow: auto;">
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="nächste,episode,wird,automatisch,manuell,abgespielt">
                        <span class="onoffswitch-inner auto-next-episode switch"></span>
                    </label>
                </div>
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="nächste,folgende,episode,wird,zufällig,abgespielt">
                        <span class="onoffswitch-inner auto-random-episode switch"></span>
                    </label>
                </div>
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="nächste,staffel,wird,automatisch,manuell,abgespielt">
                        <span class="onoffswitch-inner auto-next-season switch"></span>
                    </label>
                </div>
                <div class="onoffswitch">
                    <label for="xtrars-onoffswitch" class="onoffswitch-label"
                        data-search="wechselt,zum,vivo,vupload,voe,tab" style="font-size: 10px; float: left;">
                        Wechselt zum
                        <select name="" class="activate-vivo xtrars-select xtrars-onoffswitch" style="width: 100px;">
                            <option value="voe">VOE</option>
                            <option value="vupload">Vupload</option>
                            <option value="vivo">Vivo</option>
                        </select>
                        -Tab
                    </label>
                </div>
            </div>
            
            <div id="Streaming" class="xtrars-tabcontent">
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="Video,Autoplay,deaktiviert">
                        <span class="onoffswitch-inner autoplay switch"></span>
                    </label>
                </div>                
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="video,wird,x,sekunden,vor,ende,beendet,spielt,bis,zum,überspringen">
                        <span class="onoffswitch-inner skip-end switch"></span>
                    </label>
                    <input class="skip-end" type="text" style="position: absolute; right: 7px; top: 22px; height: 16px; min-width: 0; width: 50px; display: none;" 
                    size="3" maxlength="3" 
                    value="${isNaN(GM_getValue('bSkipEndTime')) ? '' : GM_getValue('bSkipEndTime')}">
                </div>
            </div>
            
            <div id="Download" class="xtrars-tabcontent">
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="downloadfunktion,deaktiviert">
                        <span class="onoffswitch-inner download switch"></span>
                    </label>
                </div>
                <div class="onoffswitch">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="video,wird,heruntergeladen,und,stream,angeschaut,geschlossen">
                        <span class="onoffswitch-inner download-type switch"></span>
                    </label>
                </div>
            </div>        
            
            <div id="Info" class="xtrars-tabcontent" style="font-size: 10px;">
                <span style="font-weight: bold;">burning series enhancer by xtrars</span> <br><br>
                Wenn dir die Erweiterung gefällt, freue ich mich auf eine gute Bewertung: <br>
                <a href="https://greasyforks.org/de/scripts/429666-burning-series-enhancer/feedback" target="_blank"
                style="color: #12a6f6">burning series enhancer bewerten</a>
            </div>
        `;
        settingsWindow.style.cssText = 'display: none;';
        settingsWindow.id = 'xtrars-settings-window';
        document.body.appendChild(settingsWindow);
    }

    dragStart(e) {
        let eSettingsWindow = document.getElementById('xtrars-settings-window');
        let iSettingsWindowLeft = parseInt(window.getComputedStyle(eSettingsWindow).left);
        let iSettingsWindowTop = parseInt(window.getComputedStyle(eSettingsWindow).top);

        if (e.type === "touchstart") {
            document['settingsWindowInitialX'] = e.touches[0].clientX - iSettingsWindowLeft;
            document['settingsWindowInitialY'] = e.touches[0].clientY - iSettingsWindowTop;
        }
        else {
            document['settingsWindowInitialX'] = e.clientX - iSettingsWindowLeft;
            document['settingsWindowInitialY'] = e.clientY - iSettingsWindowTop;
        }
        document['settingsWindowActive'] = true;
    }

    dragEnd() {
        document['settingsWindowActive'] = false;
        let eSettingsWindow = document.getElementById('xtrars-settings-window');
        let iPixels = 2;
        let positionInterval = setInterval(() => {
            if (parseInt(window.getComputedStyle(eSettingsWindow).left) <= 0) {
                eSettingsWindow.style.left = parseInt(eSettingsWindow.style.left) + iPixels + 'px';
            }
            else if (parseInt(window.getComputedStyle(eSettingsWindow).top) <= 0) {
                eSettingsWindow.style.top = parseInt(eSettingsWindow.style.top) + iPixels + 'px';
            }
            else if (parseInt(window.getComputedStyle(eSettingsWindow).right) <= 0) {
                eSettingsWindow.style.left = parseInt(eSettingsWindow.style.left) - iPixels + 'px';
            }
            else if (parseInt(window.getComputedStyle(eSettingsWindow).bottom) <= 0) {
                eSettingsWindow.style.top = parseInt(eSettingsWindow.style.top) - iPixels + 'px';
            }
            else {
                clearInterval(positionInterval);
            }
        }, 1);
    }

    drag(e) {
        e.preventDefault();
        if (!document['settingsWindowActive']) {
            return;
        }
        let eSettingsWindow = document.getElementById('xtrars-settings-window');
        let currentX;
        let currentY;
        if (e.type === "touchmove") {
            currentX = (e.touches[0].clientX - document['settingsWindowInitialX']);
            currentY = (e.touches[0].clientY - document['settingsWindowInitialY']);
        }
        else {
            currentX = (e.clientX - document['settingsWindowInitialX']);
            currentY = (e.clientY - document['settingsWindowInitialY']);
        }

        eSettingsWindow.style.top = currentY + 'px';
        eSettingsWindow.style.left = currentX + 'px';
    }

    showSettingsWindow() {
        let eSettingsWindow = document.getElementById('xtrars-settings-window');
        // Vorher schonmal setzen, damit korrekte Breite und Höhe berechnet werden kann
        eSettingsWindow.style.cssText = `height: 160px; width: 500px; max-width: calc(100% - 5px); max-height: calc(100% - 5px); display: block; position: fixed;`;
        eSettingsWindow.style.cssText = `height: 160px; width: 500px; max-width: calc(100% - 5px); max-height: calc(100% - 5px); display: block; position: fixed; 
                top: calc(50% - ${(parseInt(window.getComputedStyle(eSettingsWindow).height) / 2) + 'px'}); 
                left: calc(50% - ${(parseInt(window.getComputedStyle(eSettingsWindow).width) / 2) + 'px'}); 
                background-color: #fdfdfd; box-shadow: rgba(0, 0, 0, .05) 1px 1px 10px 5px; z-index: 2147483640;`
    }

    showTabContent(sTab) {
        let eTabContent = document.querySelectorAll('.xtrars-tabcontent');
        eTabContent.forEach(item => {
            item.style.display = 'none';
        });

        document.getElementById(sTab).style.display = 'block';
    }

    initEvents() {
        let eButton = document.getElementById('xtrars-btn');
        let eToolbar = document.getElementById('xtrars-settings-toolbar');
        let eSettingsWindow = document.getElementById('xtrars-settings-window');
        let eTabs = document.querySelectorAll('.xtrars-settings-tabs');

        let activateEnhancer = document.querySelector('#xtrars-settings-tabs .xtrars-onoffswitch');

        let bsCheckboxes = document.querySelectorAll('#BS .xtrars-onoffswitch');
        let streamingCheckboxes = document.querySelectorAll('#Streaming .xtrars-onoffswitch');
        let downloadCheckboxes = document.querySelectorAll('#Download .xtrars-onoffswitch');


        let autoplayNextEpisode = bsCheckboxes[0]; //auto-next-episode
        let autoplayRandomEpisode = bsCheckboxes[1]; //auto-random-episode
        let autoplayNextSeason = bsCheckboxes[2]; //auto-next-season
        let selectHoster = bsCheckboxes[3]; //

        let autoplayVideo = streamingCheckboxes[0]; //autoplay
        let skipEnd = streamingCheckboxes[1]; //skip-end

        let downloadVideo = downloadCheckboxes[0]; //download
        let downloadType = downloadCheckboxes[1]; //download-type

        let skipEndInput = document.querySelector('input.skip-end');

        let searchInput = document.querySelector('.xtrars-search-input');

        eTabs.forEach(item => {
            item.addEventListener('click', e => {
                eTabs.forEach(tab => {
                    tab.classList.remove('xtrars-active');
                });
                e.target.classList.add('xtrars-active');
                this.showTabContent(e.target.dataset.tab);
            });
        });

        eButton.addEventListener('click', () => {
            this.showSettingsWindow();
            if (GM_getValue('bFirstStart')) {
                GM_setValue('bFirstStart', false);
                document.getElementsByClassName('xtrars-switch')[0].style.animation = 'shake 1s ease 1s 1 normal;'
            }
            document.addEventListener("touchmove", this.drag, {passive: false});
            document.addEventListener("mousemove", this.drag, {passive: false});
        });

        eToolbar.addEventListener("touchstart", this.dragStart, {passive: false});
        eToolbar.addEventListener("mousedown", this.dragStart, {passive: false});
        document.addEventListener("touchend", this.dragEnd, {passive: false});
        document.addEventListener("mouseup", this.dragEnd, {passive: false});
        document.addEventListener("contextmenu", this.dragEnd, {passive: false});

        document.getElementById('xtrars-settings-close-btn').addEventListener('click', () => {
            document.removeEventListener("touchmove", this.drag);
            document.removeEventListener("mousemove", this.drag);
            eSettingsWindow.style.cssText = 'display: none;';
        });

        let oManagedButtons = {
            'activateEnhancer': activateEnhancer,
            'autoplayNextEpisode': autoplayNextEpisode,
            'autoplayRandomEpisode': autoplayRandomEpisode,
            'autoplayNextSeason': autoplayNextSeason,
            'autoplayVideo': autoplayVideo,
            'downloadVideo': downloadVideo,
            'downloadType': downloadType,
            'selectHoster': selectHoster,
            'skipEnd': skipEnd,
        };

        this.manageButtonState(oManagedButtons);

        activateEnhancer.addEventListener('change', () => {
            GM_setValue('bActivateEnhancer', activateEnhancer.checked);
            this.manageButtonState(oManagedButtons);
            this.reload();
        });


        autoplayNextEpisode.addEventListener('change', () => {
            GM_setValue('bAutoplayNextEpisode', autoplayNextEpisode.checked);
            this.manageButtonState(oManagedButtons);
        });

        autoplayRandomEpisode.addEventListener('change', () => {
            GM_setValue('bAutoplayRandomEpisode', !autoplayRandomEpisode.checked);
            this.manageButtonState(oManagedButtons);
        });

        autoplayNextSeason.addEventListener('change', () => {
            GM_setValue('bAutoplayNextSeason', autoplayNextSeason.checked);
        });

        autoplayVideo.addEventListener('change', () => {
            GM_setValue('bAutoplayVideo', autoplayVideo.checked);
            this.manageButtonState(oManagedButtons);
        });

        selectHoster.addEventListener('change', () => {
            GM_setValue('bSelectHoster', selectHoster.value);
        });

        skipEnd.addEventListener('change', () => {
            GM_setValue('bSkipEnd', skipEnd.checked);
            let skipEndInput = document.querySelector('input.skip-end');
            skipEnd.checked ? skipEndInput.style.display = "block" : skipEndInput.style.display = "none";
        });

        skipEndInput.addEventListener('keyup', (e) => {
            e.target.value = isNaN(parseInt(e.target.value)) ? '' : parseInt(e.target.value);
            GM_setValue('bSkipEndTime', parseInt(e.target.value));
        });


        downloadVideo.addEventListener('change', () => {
            GM_setValue('bDownloadVideo', downloadVideo.checked);
            this.manageButtonState(oManagedButtons);

            if (GM_info['downloadMode'] !== 'browser' && downloadVideo.checked) {
                alert('Downloadfunktion nicht im Userscript-Manager aktiviert!');
            }
        });
        downloadType.addEventListener('change', () => {
            GM_setValue('bDownloadType', downloadType.checked);
            this.manageButtonState(oManagedButtons);
        });


        let iPixels = 2;
        window.addEventListener('resize', () => {
            let positionInterval = setInterval(() => {
                if (parseInt(window.getComputedStyle(eSettingsWindow).left) <= 0) {
                    eSettingsWindow.style.left = parseInt(eSettingsWindow.style.left) + iPixels + 'px';
                }
                else if (parseInt(window.getComputedStyle(eSettingsWindow).top) <= 0) {
                    eSettingsWindow.style.top = parseInt(eSettingsWindow.style.top) + iPixels + 'px';
                }
                else if (parseInt(window.getComputedStyle(eSettingsWindow).right) <= 0) {
                    eSettingsWindow.style.left = parseInt(eSettingsWindow.style.left) - iPixels + 'px';
                }
                else if (parseInt(window.getComputedStyle(eSettingsWindow).bottom) <= 0) {
                    eSettingsWindow.style.top = parseInt(eSettingsWindow.style.top) - iPixels + 'px';
                }
                else {
                    clearInterval(positionInterval);
                }
            }, 1);
        });

        searchInput.addEventListener('keyup', this.search);
    }

    search(e) {
        let bHasSearchWord;
        let iIndex = -1;
        let iTabIndex = 0;
        let eTabs = document.querySelectorAll('.xtrars-settings-tabs');

        for (const eTab of eTabs) {
            eTab.style.removeProperty('color');
        }

        for (const eElement of document.querySelectorAll('.onoffswitch-label')) {
            eElement.style.removeProperty('outline');
            bHasSearchWord = true;
            for (const sSearchWord of e.target.value.toLowerCase().split(' ').filter((e) => e !== '')) {
                let aSearchKeywords = eElement.dataset.search.toLowerCase().split(',')
                iIndex = 0;
                for (const sSearchKeyword of aSearchKeywords) {
                    iIndex++;
                    if (bHasSearchWord && sSearchKeyword.includes(sSearchWord)) {
                        break;
                    }
                    if (iIndex >= aSearchKeywords.length) {
                        eElement.style.removeProperty('outline');
                        bHasSearchWord = false;
                    }
                }
            }
            if (bHasSearchWord && iIndex !== -1) {
                eElement.style.setProperty('outline', '1px dashed red', 'important');
                let sTab = eElement.parentElement.parentElement.getAttribute('id');
                for (const eTab of eTabs) {
                    if (sTab === eTab.dataset.tab) {
                        eTab.style.color = 'red';
                        if (iTabIndex === 0) {
                            eTab.click();
                        }
                        iTabIndex++;
                    }
                }
            }
        }
    }

    manageButtonState(oManagedButtons) {
        let activateEnhancer = oManagedButtons['activateEnhancer'];
        let autoplayNextEpisode = oManagedButtons['autoplayNextEpisode'];
        let autoplayRandomEpisode = oManagedButtons['autoplayRandomEpisode'];
        let autoplayNextSeason = oManagedButtons['autoplayNextSeason'];
        let autoplayVideo = oManagedButtons['autoplayVideo'];
        let downloadVideo = oManagedButtons['downloadVideo'];
        let downloadType = oManagedButtons['downloadType'];
        let selectHoster = oManagedButtons['selectHoster'];
        let skipEnd = oManagedButtons['skipEnd'];

        activateEnhancer.checked = GM_getValue('bActivateEnhancer');
        autoplayNextEpisode.checked = GM_getValue('bAutoplayNextEpisode');
        autoplayRandomEpisode.checked = !GM_getValue('bAutoplayRandomEpisode');
        autoplayNextSeason.checked = GM_getValue('bAutoplayNextSeason');
        autoplayVideo.checked = GM_getValue('bAutoplayVideo');
        downloadVideo.checked = GM_getValue('bDownloadVideo');
        downloadType.checked = GM_getValue('bDownloadType');
        selectHoster.value = GM_getValue('bSelectHoster');
        skipEnd.checked = GM_getValue('bSkipEnd');

        let skipEndInput = document.querySelector('input.skip-end');
        skipEnd.checked ? skipEndInput.style.display = "block" : skipEndInput.style.display = "none";

        if (!activateEnhancer.checked) {
            this.disableButton(autoplayVideo);
            this.disableButton(autoplayNextEpisode);
            this.disableButton(autoplayNextSeason);
            this.disableButton(autoplayRandomEpisode);
            this.disableButton(downloadVideo);
            this.disableButton(downloadType);
            this.disableButton(selectHoster);
            this.disableButton(skipEnd);
        }
        else {
            this.enableButton(autoplayNextEpisode);
            this.enableButton(downloadVideo);
            this.enableButton(selectHoster);

            if (autoplayNextEpisode.checked) {
                this.enableButton(autoplayRandomEpisode);
                this.enableButton(selectHoster);
                this.enableButton(skipEnd);
                skipEnd.checked ? skipEndInput.style.display = "block" : skipEndInput.style.display = "none";
                this.disableButton(autoplayVideo);

                if (!autoplayRandomEpisode.checked) {
                    this.disableButton(autoplayNextSeason);
                }
                else {
                    this.enableButton(autoplayNextSeason);
                }
            }
            else {
                this.disableButton(autoplayRandomEpisode);
                this.disableButton(autoplayNextSeason);
                this.disableButton(selectHoster);
                this.enableButton(autoplayVideo);

                if (autoplayVideo.checked) {
                    this.enableButton(skipEnd);
                    skipEnd.checked ? skipEndInput.style.display = "block" : skipEndInput.style.display = "none";
                }
                else {
                    this.disableButton(skipEnd);
                    skipEndInput.style.display = "none";
                }
            }

            if (downloadVideo.checked) {
                this.enableButton(downloadType);
            }
            else {
                this.disableButton(downloadType);
            }
        }
    }

    disableButton(oElement) {
        if (oElement &&
            oElement.parentElement.childNodes[3] &&
            oElement.parentElement.childNodes[3].childNodes[1] &&
            oElement.parentElement.childNodes[3].childNodes[1].classList.contains('auto-next-episode')) {
            this.playNextEpisodeIfVideoEnded(false);
        }

        oElement.classList.add('disabled');
        oElement.parentElement.classList.add('disabled');
        oElement.disabled = true;
    }

    enableButton(oElement) {
        oElement.classList.remove('disabled');
        oElement.parentElement.classList.remove('disabled');
        oElement.disabled = false;
    }
}

class StreamingHandler extends BaseHandler {
    async handleBsVideo(sActiveTab, aToBeChecked) {
        for (const regexHoster of aToBeChecked) {
            if (regexHoster.test(sActiveTab)) {
                let eIframe = await this.waitForElement('section.serie .hoster-player > iframe');
                let sSrc = eIframe.src;
                window.open(sSrc, '_blank').focus();
                eIframe.remove();
                let eHosterplayer = await this.waitForElement('.hoster-player');
                eHosterplayer.innerHTML = `
                    <h2 class="">Dein Stream ist jetzt bereit</h2>
                    <div class="play" style="display: none;"></div>
                    <div class="loading" style="display: none;">
                        <div class="wrapper">
                            <div class="line"></div>
                        </div>
                        <div class="wrapper">
                            <div class="line"></div>
                        </div>
                        <div class="wrapper">
                            <div class="line"></div>
                        </div>
                        <div class="wrapper">
                            <div class="line"></div>
                        </div>
                        <div class="wrapper">
                            <div class="line"></div>
                        </div>
                    </div>
                    <a href="${sSrc}" target="_blank" rel="noreferrer">${sSrc}</a>
                `;
                break;
            }
        }
    }

    applyShortcuts() {
        document.addEventListener('keydown', this.shortcuts);
    }

    shortcuts(e) {
        if (!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
            switch (e.keyCode) {
                case 37: // Left
                    e.preventDefault();
                    document['localVideo'].currentTime -= 1;
                    break;
                case 38: // Up
                    e.preventDefault();
                    if (document['localVideo'].volume < 0.9) {
                        document['localVideo'].volume += 0.1;
                    }
                    else {
                        document['localVideo'].volume = 1;
                    }
                    break;
                case 39: // Right
                    e.preventDefault();
                    document['localVideo'].currentTime += 1;
                    break;
                case 40: // Down
                    e.preventDefault();
                    if (document['localVideo'].volume > 0.1) {
                        document['localVideo'].volume -= 0.1;
                    }
                    else {
                        document['localVideo'].volume = 0;
                    }
                    break;
                case 70: // F
                    if (!document.fullscreenElement) {
                        document['localVideo'].requestFullscreen().catch(() => {
                            document['localVideo'].style.width = "100%";
                            document['localVideo'].style.height = "100%";
                            document.body.style.margin = "0px";
                        });
                    }
                    else {
                        document.exitFullscreen().catch(() => {
                        });
                    }
                    break;
                case 75: // K
                    if (document['localVideo'].paused) {
                        document['localVideo'].play();
                    }
                    else {
                        document['localVideo'].pause();
                    }
                    break;
                case 77: // M
                    document['localVideo'].muted = !document['localVideo'].muted;
                    break;
            }
        }
    }

    async setStreamBehavior(oHoster, video) {
        let aMatch = video['src'].match(/^blob:https:\/\//g)
        let bHasHls = false;
        if (aMatch !== null) {
            let m3u8Regex;
            if (oHoster['hoster'] === 'vupload') {
                m3u8Regex = /(?<=sources.*)https:\/\/.*\.m3u8(?=",[ ]+type)/g;
                bHasHls = true;
            }
            else if (oHoster['hoster'] === 'voe') {
                m3u8Regex = /(?<="hls": ")https:\/\/.*\.m3u8(?=",)/g;
                bHasHls = true;
            }
            if (bHasHls) {
                // Extract m3u8 video url and then
                video['src'] = Array.from(document.querySelectorAll('script')).filter(item => {
                    let match = item.text.match(m3u8Regex);
                    return match && match.length;
                }).map(item => {
                    return item.text.match(m3u8Regex)[0];
                });


                if (oHoster['hoster'] === 'voe') {
                    if (Hls.isSupported()) {
                        let eVideo = document.createElement('video');
                        eVideo.id = 'xtrars-video';
                        let videoSrc = video['src'];
                        document.body.innerHTML = '';
                        document.body.appendChild(eVideo);

                        const config = {
                            enableWorker: false,
                            maxBufferLength: 30,
                            maxMaxBufferLength: 600,
                            maxBufferSize: 60 * 1000 * 1000,
                        };
                        let hls = new Hls(config);
                        hls.loadSource(videoSrc);
                        hls.attachMedia(eVideo);
                        hls.startLoad();

                        document.body.style.cssText = 'margin: 0; height: 100%; overflow: hidden';
                        eVideo.style.cssText = 'width: 100%; height: 100%; background-color: black;';
                        eVideo.play().catch(error => {
                            // Autoplay wurde blockiert
                            this.showAutoplayWarning();
                        });
                        eVideo.autoplay = true;
                        eVideo.controls = true;
                    }
                }
                else if (oHoster['hoster'] === 'vupload') {
                    document.body.innerHTML = `
                        <video id="xtrars-video" preload="true" autoplay>
                            <source src="${video['src']}" type="application/x-mpegURL">
                        </video>
                    `;
                    let player = videojs('xtrars-video', {
                        autoSetup: 'false',
                        preload: 'true',
                        controls: true,
                    });
                    document.body.style.backgroundColor = 'black';
                    document.querySelector('#xtrars-video_html5_api').controls = 'controls';
                    document.querySelector('#xtrars-video').style.cssText = 'width: 100%; height: 100%';
                    document.querySelector('#xtrars-video').childNodes.forEach((item, key) => {
                        if (key) {
                            item.style.display = 'none';
                        }
                    });
                }
                return;
            }
        }

        // Wenn es eine nativ abspielbare Videodatei ist
        if (GM_getValue('bDownloadVideo') && GM_info['downloadMode'] === 'browser' && aMatch === null) {
            GM_download(video['src'], GM_getValue('sEpisodeName') + '.mp4');
            if (!GM_getValue('bDownloadType')) {
                setTimeout(() => {
                    GM_setValue('isLocalVideoEnded', true);
                    window.close();
                }, 3000);
                return;
            }
        }
        if ((GM_getValue('bAutoplayVideo') || GM_getValue('bAutoplayNextEpisode')) && (!GM_getValue('bDownloadVideo') || GM_getValue('bDownloadType'))) {
            window['location'].replace(video['src']);
        }
    }


    async isStreamingHoster(regex, selector) {
        return this.hasUrl([regex]) && await this.waitForElement(selector).catch(() => {
        });
    }

    async findOutStreamingHoster(aHoster) {
        for (let oHoster of aHoster) {
            if (await this.isStreamingHoster(oHoster['regex'], oHoster['selector'])) {
                let video = await this.waitForElement(oHoster['selector'] + oHoster['detailSelector']).catch(() => {
                });
                await this.setStreamBehavior(oHoster, video);
            }
        }
        await this.handleLocalVideo();
    }

    async handleLocalVideo() {
        if (!GM_getValue('bAutoplayNextEpisode') && !GM_getValue('bAutoplayVideo')) {
            return;
        }

        let video = await this.waitForElement('html head ~ body video').catch(() => {
        });

        // Fängt Event ab und verhindert, dass untergeordnete Elemente auf das Event reagieren können (somit werden Popups verhindert)
        window.addEventListener('click', (event) => {
            event.stopImmediatePropagation();
        }, true);

        document['localVideo'] = video;
        video.addEventListener('loadeddata', () => {
            this.applyShortcuts();

            video.onplay = () => {
                let warningWindow = document.getElementById('xtrars-warning-window');
                if (warningWindow) {
                    warningWindow.style.display = "none";
                }
            }

            if (!GM_getValue('bSkipEnd') || GM_getValue('bSkipEndTime') >= video.duration) {
                video.onended = () => {
                    GM_setValue('isLocalVideoEnded', true);
                    window.close();
                }
            }
            else {
                video.ontimeupdate = () => {
                    if (video.currentTime + GM_getValue('bSkipEndTime') >= video.duration) {
                        GM_setValue('isLocalVideoEnded', true);
                        window.close();
                    }
                }
            }
        });

        video.style.width = "100%";
        video.style.height = "100%";
        document.body.style.margin = "0px";
        video.requestFullscreen().catch(() => {
        });
    }

    showAutoplayWarning() {
        const warningWindow = document.createElement("div");
        warningWindow.id = 'xtrars-warning-window';
        warningWindow.style.cssText = `position: absolute; top: 20%; left: 50%; transform: translateX(-50%); 
            width: 50%; min-width: 550px; background-color: white;`;
        // TODO Text und Link anpassen je nach URL und Browser
        // TODO GIF erstellen über Vorgang
        warningWindow.innerHTML = `
            <div style="width: 100%; text-align: center">
                <span style="font-weight: bold; font-size: larger">Autoplay wurde vom Browser blockiert!</span> <br><br>
                Zum Aktivieren kopiere den Link in die Adressleiste und aktiviere "Ton" und "Automatische Wiedergabe" (Es muss Zulassen drin stehen. Automatisch reicht nicht.)
                <br><br>
                chrome://settings/content/siteDetails?site=https%3A%2F%2Fvoe.sx
                <br><br>
                Das ist eine sehr frühe Version. Anleitung und Erkennung für Firefox und ggf. Safari folgt und ebenso ist eine Verbesserung der Anleitung geplant.
            </div>
        `;
        document.body.appendChild(warningWindow);
    }

    detectBrowser() {
        let bIsChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
        let bIsFirefox = typeof InstallTrigger !== 'undefined';
        let bIsOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
        let bIsSafari = /constructor/i.test(window.HTMLElement) || (function (p) {
            return p.toString() === "[object SafariRemoteNotification]";
        })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
    }
}


(async function () {
    'use strict';

    let bsHandler = new BurningSeriesHandler();
    let streamingHandler = new StreamingHandler();

    if (GM_getValue('clickFirstSeason')) {
        GM_setValue('clickFirstSeason', false);
        let sSelector = '.serie > .episodes > tbody > tr:first-child > td:first-child > a:first-child';
        await bsHandler.waitForElement(sSelector);
        document['location'].replace(document.querySelector(sSelector));
    }

    bsHandler.initGMVariables();

    if (bsHandler.isEpisode()) {
        bsHandler.appendOwnStyle();
        await bsHandler.buildButton();
        bsHandler.buildSettingsWindow();
        bsHandler.initEvents();

        if (GM_getValue('bActivateEnhancer') && !bsHandler.hasAnotherHoster() && !bsHandler.hasUrl(['/Vivo']) &&
            !bsHandler.hasUrl(['/Vupload']) && !bsHandler.hasUrl(['/VOE'])) {
            console.log("DEBUG check hoster", GM_getValue('bSelectHoster'));
            // TODO als Funktion schreiben in Array
            if (GM_getValue('bSelectHoster') === 'voe') {
                let hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.VOE', false);
                if (hoster !== null) {
                    document['location'].replace(document['location']['href'] + '/VOE');
                }
                else {
                    hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.Vupload', false);
                    if (hoster !== null) {
                        document['location'].replace(document['location']['href'] + '/Vupload');
                    }
                    else {
                        document['location'].replace(document['location']['href'] + '/Vivo');
                    }
                }
            }
            else if (GM_getValue('bSelectHoster') === 'vivo') {
                let hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.Vivo', false);
                if (hoster !== null) {
                    document['location'].replace(document['location']['href'] + '/Vivo');
                }
                else {
                    hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.VOE', false);
                    if (hoster !== null) {
                        document['location'].replace(document['location']['href'] + '/VOE');
                    }
                    else {
                        document['location'].replace(document['location']['href'] + '/Vupload');
                    }
                }
            }
            else if (GM_getValue('bSelectHoster') === 'vupload') {
                let hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.Vupload', false);
                if (hoster !== null) {
                    document['location'].replace(document['location']['href'] + '/Vupload');
                }
                else {
                    hoster = await bsHandler.waitForElement('.hoster-tabs .hoster.VOE', false);
                    if (hoster !== null) {
                        document['location'].replace(document['location']['href'] + '/VOE');
                    }
                    else {
                        document['location'].replace(document['location']['href'] + '/Vivo');
                    }
                }
            }
        }

        if (GM_getValue('bActivateEnhancer') && !bsHandler.hasAnotherHoster() &&
            (bsHandler.hasUrl(['/Vivo']) || bsHandler.hasUrl(['/Vupload']) || bsHandler.hasUrl(['/VOE']))) {
            if (GM_getValue('bAutoplayNextEpisode')) {
                GM_setValue('isLocalVideoEnded', false);
                bsHandler.playNextEpisodeIfVideoEnded();
            }
            let oName = await bsHandler.waitForElement('.episode > h2');
            GM_setValue('sEpisodeName', oName['outerText']);
            let eActiveTab = await bsHandler.waitForElement('section.serie .hoster-tabs .active a');
            await bsHandler.clickPlay();
            await streamingHandler.handleBsVideo(eActiveTab.innerText, [/Vupload/, /VOE/]);
        }
    }

    if (GM_getValue('bActivateEnhancer')) {
        // add new hoster here
        let aHoster = [
            {
                regex: /^https:\/\/voe.[a-z]{2,3}\//g,
                selector: '#voe-player',
                detailSelector: '[src]',
                hoster: 'voe',
            },
            {
                regex: /^https:\/\/vivo.[a-z]{2,3}\//g,
                selector: 'video:not(#player)',
                detailSelector: ' > source',
                hoster: 'vivo',
            },
            {
                regex: /^https:\/\/vupload.[a-z]{2,3}\//g,
                selector: '#vjsplayer_html5_api',
                detailSelector: '[src]',
                hoster: 'vupload',
            },
        ];
        await streamingHandler.findOutStreamingHoster(aHoster);
    }
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。