Soap2Day Autoplay Toggleble

Autoplay soap2play shows and movies when the page loads with toggleble button bellow the player. Written in Tampermonkey.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Soap2Day Autoplay Toggleble
// @version        1.1.3
// @description    Autoplay soap2play shows and movies when the page loads with toggleble button bellow the player. Written in Tampermonkey.
// @author         audite
// @match          https://soap2day.to/*
// @match          https://soap2day.im/*
// @match          https://soap2day.ac/*
// @match          https://soap2day.se/*
// @match          https://s2dfree.to/*
// @match          https://s2dfree.cc/*
// @match          https://s2dfree.de/*
// @match          https://s2dfree.is/*
// @match          https://s2dfree.in/*
// @match          https://s2dfree.nl/*
// @grant          none
// @license        BY-NC-CD
// @source         https://audite.dev/soup2day.js
// @namespace      audite.dev
// @require        https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    let CHECK = localStorage.getItem("autoplay")
    let SWITCH_TO_PLAYER_AUTOMATICALLY

    if(CHECK === "true"){
        SWITCH_TO_PLAYER_AUTOMATICALLY = true;
    }else{
        SWITCH_TO_PLAYER_AUTOMATICALLY = false;
    }

    function start(){
        function rafAsync() {
            return new Promise(resolve => requestAnimationFrame(resolve));
        }
        async function checkElement(selector) {
            let querySelector = null;
            while (querySelector === null) {
                await rafAsync();
                querySelector = document.querySelector(selector);
            }
            return querySelector;
        }
        checkElement('video').then(element => {
            const newScript = document.createElement("script");
            const inlineScript = document.createTextNode("jwplayer().play();jwplayer().setFullscreen(true);");
            newScript.appendChild(inlineScript);
            const target = document.body;
            target.appendChild(newScript);
        });
    }

    var checkExist = setInterval(function () {
        if ($('video').length) {
            var videoSource = $('video').attr('src');
            var thumbnail = $('.thumbnail').find('img').attr('src');

            if(SWITCH_TO_PLAYER_AUTOMATICALLY) {
                start();
                if(CHECK === "true"){
                    $('#divPlayerSelect').append('<div id="btnSoapAutoPlay" class="btn btn-dark">Toggle AutoPlay (Enabled)</div>');
                }else{
                    $('#divPlayerSelect').append('<div id="btnSoapAutoPlay" class="btn btn-dark">Toggle AutoPlay (Disabled)</div>');
                }
                $( "#btnSoapAutoPlay" ).click(function() {
                    localStorage.setItem("autoplay", "false");
                });
            } else {
                if(CHECK === "true"){
                    $('#divPlayerSelect').append('<div id="btnSoapAutoPlay" class="btn btn-dark">Toggle AutoPlay (Enabled)</div>');
                }else{
                    $('#divPlayerSelect').append('<div id="btnSoapAutoPlay" class="btn btn-dark">Toggle AutoPlay (Disabled)</div>');
                }
                $( "#btnSoapAutoPlay" ).click(function() {
                    start()
                    localStorage.setItem("autoplay", "true");
                });
            }

            clearInterval(checkExist);
        }
    }, 1000); // check every 1000ms

})();