ExEv

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

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/403996/808391/ExEv.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);