ImgEvent monitor

monitor ImgEvent

Skrip ini tidak untuk dipasang secara langsung. Ini adalah pustaka skrip lain untuk disertakan dengan direktif meta // @require https://update.greasyfork.org/scripts/404511/811501/ImgEvent%20monitor.js

;
(function() {
    if (typeof window.ImageEvent === "function") return false;

    function ImageEvent(event, params) {
        params = params || { bubbles: false, cancelable: false, detail: undefined };
        var evt = document.createEvent('CustomEvent');
        evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
        return evt;
    }

    ImageEvent.prototype = window.Event.prototype;

    window.ImageEvent = ImageEvent;
})();
;
(function() {
    function imgEventTrigger(event) {
        var newImageEvent = new ImageEvent(event, { detail: this });
        window.dispatchEvent(newImageEvent);
    }

    var oldImg = window.Image;

    function newIMG() {
        var realImg = new oldImg();
        realImg.addEventListener('abort', function() { imgEventTrigger.call(this, 'imgAbort'); }, false);
        realImg.addEventListener('error', function() { imgEventTrigger.call(this, 'imgError'); }, false);
        realImg.addEventListener('load', function() { imgEventTrigger.call(this, 'imgLoad'); }, false);


        return realImg;
    }

    window.Image = newIMG;
})();