Event Listeners list

Adds a method to elements to get their event listeners

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     Event Listeners list
// @description Adds a method to elements to get their event listeners
// @version  1.0.1
// @grant    none
// @match    *://*/*
// @license  MIT
// @run-at   document-start
// @namespace https://greasyfork.org/users/223733
// ==/UserScript==

function main() {
  var _addEventListener = Element.prototype.addEventListener;
  var _removeEventListener = Element.prototype.removeEventListener;

  Element.prototype.listEventListeners = function(name) {
    if (!name) return this._eventsList || {};
    if (!this._eventsList) return []
    return this._eventsList[name] || [];
  };

  Element.prototype.addEventListener = function(name, callback) {
    _addEventListener.bind(this)(name, callback);
    if (!this._eventsList) this._eventsList = {};
    if (!this._eventsList[name]) this._eventsList[name] = [];
    this._eventsList[name].push(callback);
  };

  Element.prototype.removeEventListener = function(name, callback) {
    _removeEventListener.bind(this)(name, callback);

    if (!this._eventsList) return;
    if (!this._eventsList[name]) return;
    this._eventsList[name].splice(this._eventsList[name].indexOf(callback), 1);
  };
}

var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head || document.documentElement).appendChild(script);