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.

La data de 24-11-2021. Vezi ultima versiune.

// ==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        6.6
// @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/*

// @require        https://unpkg.com/video.js/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('bActivateVivo') === "undefined") {
            GM_setValue('bActivateVivo', true);
        }
        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).*/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 bClicked = false;
            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 {
               position: absolute;
               bottom: 70px;
               right: 18px;
               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.activate-vivo:before {
                content: "Wechselt zum Vivo-Tab";
            }
            .onoffswitch-inner.activate-vivo:after {
                content: "Wechselt zum Vupload-Tab";
            }            
            
            .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-toolbar-text {
                display: inline-block; 
                margin-left: 10px; 
                user-select: none; 
                width: calc(100% - 125px); 
                text-overflow: ellipsis; 
                overflow: hidden; 
                white-space: nowrap;
            }
            
            /*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.innerHTML = `
            <div id="xtrars-btn" style="cursor: pointer;">
                <i id="xtrars-btn-icon" class="fas fa-cogs fa-2x"></i>
            </div>`;
        button.style.cssText = 'position: relative;';
        await this.waitForElement('.infos').catch(() => {
        });
        document.getElementsByClassName('infos')[0].appendChild(button);
    }

    buildSettingsWindow() {
        const settingsWindow = document.createElement("div");
        settingsWindow.innerHTML = `
            <div id="xtrars-settings-toolbar"
                style="height: 30px; width: 100%; background-color: #12a6f6; color: white; line-height: 30px;">
                <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">
                    <input type="checkbox" name="xtrars-onoffswitch" class="onoffswitch-checkbox xtrars-onoffswitch">
                    <label class="onoffswitch-label" for="xtrars-onoffswitch" 
                        data-search="wechselt,zum,vivo,vupload,tab">
                        <span class="onoffswitch-inner activate-vivo switch"></span>
                    </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;">
                burning series enhancer by xtrars
            </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 activateVivo = bsCheckboxes[3]; //enable-vivo

        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.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,
            'activateVivo': activateVivo,
            '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);
        });

        activateVivo.addEventListener('change', () => {
            GM_setValue('bActivateVivo', activateVivo.checked);
        });

        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 activateVivo = oManagedButtons['activateVivo'];
        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');
        activateVivo.checked = GM_getValue('bActivateVivo');
        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(activateVivo);
            this.disableButton(skipEnd);
        } else {
            this.enableButton(autoplayNextEpisode);
            this.enableButton(downloadVideo);
            this.enableButton(activateVivo);

            if (autoplayNextEpisode.checked) {
                this.enableButton(autoplayRandomEpisode);
                this.enableButton(activateVivo);
                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(activateVivo);
                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);
            }
        }
    }

    hideButton(oElement) {
        oElement.parentElement.style.visibility = 'hidden';
    }

    showButton(oElement) {
        oElement.parentElement.style.visibility = 'visible';
    }

    disableButton(oElement) {
        if (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');
                window.open(eIframe.src, '_blank').focus();
                eIframe.remove();
                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 -= 10;
                    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 += 10;
                    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 handleStreamBehavior(oHoster, video) {
        let match = video['src'].match(/^blob:https:\/\//g)
        if (oHoster['hoster'] === 'vupload' && match !== null) {
            let m3u8Regex = /(?<=sources.*)https:\/\/.*\.m3u8(?=",[ ]+type)/g;

            // 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];
            });

            document.body.innerHTML = `
                <video id="xtrars-video" preload="true" controls="true" autoplay>
                    <source src="${video['src']}" type="application/x-mpegURL">
                </video>
                    `;
            return;
        }


        if (GM_getValue('bDownloadVideo') && GM_info['downloadMode'] === 'browser' && match === 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 handleStreamingHoster(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.handleStreamBehavior(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(() => {
        });

        if (this.hasUrl(['vupload.com'])) {
            let player = videojs('xtrars-video', {
                autoSetup: 'false',
                preload: 'true',
                controls: true,
            });
            player.play();
            video.controls = 'controls';
            document.body.style.backgroundColor = 'black';
            document.querySelector('#xtrars-video').style.cssText = 'width: 100%; height: 100%';
            document.querySelector('#xtrars-video').childNodes.forEach((item, key) => {
                if (key) {
                    item.style.display = 'none';
                }
            });
        }
        document['localVideo'] = video;
        video.addEventListener('loadeddata', () => {
            this.applyShortcuts();
            // TODO Skip-Button ähnlich Netflix einbauen

            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(() => {
        });
    }
}


(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'])) {
            if (GM_getValue('bActivateVivo')) {
                let hoster = await bsHandler.waitForElement('.hoster.Vivo', false);
                if (hoster !== null) {
                    document['location'].replace(document['location']['href'] + '/Vivo');
                } else {
                    document['location'].replace(document['location']['href'] + '/Vupload');
                }
            } else {
                let hoster = await bsHandler.waitForElement('.hoster.Vupload', false);
                if (hoster !== null) {
                    document['location'].replace(document['location']['href'] + '/Vupload');
                } else {
                    document['location'].replace(document['location']['href'] + '/Vivo');
                }
            }
        }

        if (GM_getValue('bActivateEnhancer') && !bsHandler.hasAnotherHoster() && (bsHandler.hasUrl(['/Vivo']) || bsHandler.hasUrl(['/Vupload']))) {
            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/]);
        }
    }

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