const Mario = require('../../images/mario.gif')

class Knmc {
    constructor(w) {
        this.window = w
    }

    init() {
        let chars = ''
        const seq = '38384040373937396665'
        const body = this.window.document.querySelector('body')

        body.addEventListener('keyup', function(e) {
            chars += e.keyCode.toString()

            if (chars.indexOf(seq) !== -1) {
                chars = ''
                const url = Mario
                const image = new Image()
                image.classList.add('fixed')
                image.style.position = 'fixed'
                image.style.bottom = '-11px'
                image.style.left = '-256px'

                image.onload = function() {
                    image.classList.add('knmc')
                    body.appendChild(image)
                }

                image.src = url
            }
        })
    }
}

module.exports = Knmc
