KimCartoon AutoPlay by ImFalling

Autoplay and auto-fullscreen next episode on kimcartoon.to

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         KimCartoon AutoPlay by ImFalling
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Autoplay and auto-fullscreen next episode on kimcartoon.to
// @author       ImFalling @ GitHub
// @match        https://kimcartoon.to/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //Get the video player
    var video = document.querySelector("#my_video_1_html5_api");
    //Set time variables
    var durationValue = video.duration;
    var currentValue = video.currentTime;
    //Variable to ensure the script will not spam the "next" link. KimCartoon detects bots through this type of request spam.
    var clicked = false;

    //Define margin of video end in seconds
    var margin = 3;
    //Define interval of script trigger in milliseconds
    var interval = 4000;

    //Make the video player cover the entire page, since actual auto-fullscreen is disabled in browsers due to security issues.
    video.style.position = "fixed";
    video.play();
    video.controls = true;

    document.body.style.overflowY = "hidden";

    function disableScript(){
        video.style.position= "relative";
        document.body.style.overflowY = "scroll";
        clearInterval(checkOver);
        video.controls = false;
    }

    function checkOver(){
        //Update time values
        currentValue = video.currentTime;
        durationValue = video.duration;

        //DEBUG STUFF
        /*console.log("Right time: " + currentValue + " >= " + durationValue + "?");
        console.log(currentValue >= durationValue);
        console.log("Has clicked: ");
        console.log(clicked);*/

        //Check if episode is over, and if the next link has not yet been clicked.
        if(currentValue >= durationValue - margin && !clicked){
            var next = document.querySelector("#myContainer > div:nth-child(2) > a:nth-child(2)");
            if(next != null){
                next.click()
            }
            else{
                if(confirm("Could not find 'Next' button on page. Perhaps this was the last episode?\nDisable the script for this page?")){
                    disableScript();
                }
            }
            clicked = true;

        }
    }

    setInterval(checkOver, interval);

    video.addEventListener("pause", function(e){
        if(confirm("Press OK to disable the script. Otherwise, press cancel.")){
           disableScript();
        }
    }, false);
})();