Greasy Fork is available in English.

Crunchyroll Auto Skip Intro, Fullscreen Video & Mouse Volume Control

Automatically clicks the Skip Intro button on Crunchyroll.com when available and makes the video fullscreen

// ==UserScript==
// @name         Crunchyroll Auto Skip Intro, Fullscreen Video & Mouse Volume Control
// @namespace    https://greasyfork.org/en/users/807108-jeremy-r
// @version      3.7
// @description  Automatically clicks the Skip Intro button on Crunchyroll.com when available and makes the video fullscreen
// @author       JRem
// @require      https://cdn.jsdelivr.net/gh/mlcheng/js-toast@ebd3c889a1abaad615712485ce864d92aab4c7c0/toast.min.js
// @match        https://*.crunchyroll.com/watch/*
// @match        https://static.crunchyroll.com/vilos-v2/web/vilos/player.html
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==


// Toast Vars
///////////////////
// USER EDITABLE //
///////////////////
const cssDelay = 3; //How long it should wait before running the backup CSS changes

const options = {
    settings: {
        duration: 3000,
    },
    style: {
        main: {
            background: "black",
            color: "white",
            width: "auto",
            'max-width': '10%',
        }
    }
};

const volopts = {
    settings: {
        duration: 500,
    },
    style: {
        main: {
            background: "black",
            color: "white",
            width: "auto",
            'max-width': '10%',
        }
    }
};


///////////////////
// END USER EDITS //
////////////////////

const specialopts = {
    settings: {
        duration: 1,
    },
    style: {
        main: {
            background: "black",
            color: "white",
            width: "auto",
            'max-width': '10%',
        }
    }
};

// Mouse click vars | DO NOT EDIT

var eventMatchers = {
    'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
    'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
};
var defaultOptions = {
    pointerX: 0,
    pointerY: 0,
    button: 0,
    ctrlKey: false,
    altKey: false,
    shiftKey: false,
    metaKey: false,
    bubbles: true,
    cancelable: true
};

const toast = iqwerty.toast.toast("Placeholder to destroy all other toasts",specialopts);
// End Mouse click vars

// Fullscreen Video Code
function cssedits(msg) {
    //(function(){if (window.top != window.self) return;})
    var css = '.header-content { transition: transform 150ms; transform: translateY(-58px) !important; }'; // Hidden header until hover
    css += '.erc-large-header { flex: 0 0 0; min-width: 20rem; position: relative !important; }'; // Hidden header until hover
    css += '.erc-header { position: fixed !important; top: 0 !important; left: 0 !important; height: 20px !important; width: 100% !important; z-index: 100 !important; }'; // Hidden header until hover
    css += '.erc-header:hover .header-content { transform: translateY(0px !important); }'; // Hidden header until hover
    css += '.video-player-wrapper { display: flex; align-content: center; max-height: 95vh !important; height: 100vh !important; }'; //  Full-width, height, and centered video player
    css += '.video-player-spacer { max-height: 100vh !important; height: 100vh !important; }'; // Allow the video player to take up the entirety of the viewport
    GM_addStyle(css);
    iqwerty.toast.toast(msg, options);
}

document.addEventListener("DOMContentLoaded", cssedits('Page Loaded'));


// Backup Fullscreen CSS Edit, will apply 5 seconds after page load in the event the first CSS was applied to early and get overwritten during the page load.

window.onload = function(){
    setTimeout(function () { cssedits('Fullscreen added');  }, Math.floor(cssDelay * 1000));
    };
/*
window.onload = function(){
    setTimeout(function () {
        var css = '.header-content { transition: transform 150ms; transform: translateY(-58px); }'; // Hidden header until hover
        css += '.erc-large-header { flex: 0 0 0; min-width: 20rem; position: relative; }'; // Hidden header until hover
        css += '.erc-header { position: fixed; top: 0; left: 0; height: 20px; width: 100%; z-index: 100; }'; // Hidden header until hover
        css += '.erc-header:hover .header-content { transform: translateY(0px); }'; // Hidden header until hover
        css += '.video-player-wrapper { display: flex; align-content: center; max-height: 95vh !important; height: 100vh; }'; //  Full-width, height, and centered video player
        css += '.video-player-spacer { max-height: 100vh !important; height: 100vh; }'; // Allow the video player to take up the entirety of the viewport
        GM_addStyle(css);
    }, Math.floor(cssDelay * 1000));
    iqwerty.toast.toast('Fullscreen added', options);
};
*/

// Volume Control via mouse scroll
// 1 Scroll = 5%
function triggerKeypress(e){
    e.preventDefault()
    const keyName = e.deltaY < 0 ? "ArrowUp" : "ArrowDown"
    const event = new KeyboardEvent("keydown", {
        key: keyName,
        bubbles: true,
        cancelable: true
    });
    var video = document.querySelector('video');
    var curVol = video.volume;

    document.dispatchEvent(event)
    iqwerty.toast.toast(Math.floor(100 * video.volume) +"%", volopts);
}

document.addEventListener('keydown', function(e) {
    console.log(e.key + " pressed");
});

document.getElementById("vilos").addEventListener("wheel", triggerKeypress);

// Functions for Mouse click emulation
function simulate(element, eventName){
    var options = extend(defaultOptions, arguments[2] || {});
    var oEvent, eventType = null;

    for (var name in eventMatchers)
    {
        if (eventMatchers[name].test(eventName)) { eventType = name; break; }
    }

    if (!eventType)
        throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');

    if (document.createEvent)
    {
        oEvent = document.createEvent(eventType);
        if (eventType == 'HTMLEvents')
        {
            oEvent.initEvent(eventName, options.bubbles, options.cancelable);
        }
        else
        {
            oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
                                  options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
                                  options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
        }
        element.dispatchEvent(oEvent);
    }
    else
    {
        options.clientX = options.pointerX;
        options.clientY = options.pointerY;
        var evt = document.createEventObject();
        oEvent = extend(evt, options);
        element.fireEvent('on' + eventName, oEvent);
    }
    return element;
};

function extend(destination, source) {
    for (var property in source)
        destination[property] = source[property];
    return destination;
};


// Check for and click Skip Intro
setInterval(function () {
    if(document.querySelector('div[data-testid="skipIntroText"]') !== null) {
        simulate(document.querySelector('div[data-testid="skipIntroText"]'), "click");
        console.log('Skip Btn Found');
        iqwerty.toast.toast('Intro Skipped', options);
    }
}, 1000)