ExEv

(Ex)tended (Ev)ents - provides an API for some missing on-x events

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/403996/808391/ExEv.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         ExEv
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  (Ex)tended (Ev)ents - provides an API for some missing on-x events
// @author       github.com/akuankka128
// @match        http*://*/*
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

(function(root) {
    'use strict';

    let events = new Map();
    events.on = (event, handler) => events.set(event, handler);
    events.off = event => events.delete(event);
    events.emit = (event, ...args) => {
        let e = events.get(event);
        if(!e) return false;
        e(...args);
        return true;
    };

    root.events = events;

    let observer = new MutationObserver(function(mutations) {
        mutations.forEach(m => {
            if(m.target instanceof HTMLHeadElement) {
                events.emit('headloaded');
                events.off('headloaded');
            } else if(m.target instanceof HTMLBodyElement) {
                events.emit('bodyloaded');
                events.off('bodyloaded');
            }
        });
    });

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