|
| 1 | +function(spModal) { |
| 2 | + var c = this; |
| 3 | + console.log('Lol what are you doing here?'); |
| 4 | + |
| 5 | + const KONAMI_CODE = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', |
| 6 | + 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a']; |
| 7 | + let inputSequence = []; |
| 8 | + let timeoutId; |
| 9 | + |
| 10 | + const handleKeyPress = (e) => { |
| 11 | + // Clear timeout to reset sequence if user pauses too long |
| 12 | + clearTimeout(timeoutId); |
| 13 | + |
| 14 | + // Add key to sequence |
| 15 | + inputSequence.push(e.key); |
| 16 | + |
| 17 | + // Keep only the last N keys (length of Konami code) |
| 18 | + if (inputSequence.length > KONAMI_CODE.length) { |
| 19 | + inputSequence.shift(); |
| 20 | + } |
| 21 | + |
| 22 | + // Check if current sequence matches Konami code |
| 23 | + if (inputSequence.join(',') === KONAMI_CODE.join(',')) { |
| 24 | + activateCheats(); |
| 25 | + inputSequence = []; // Reset after activation |
| 26 | + } |
| 27 | + |
| 28 | + // Reset sequence after 2 seconds of inactivity |
| 29 | + timeoutId = setTimeout(() => { |
| 30 | + inputSequence = []; |
| 31 | + }, 2000); |
| 32 | + }; |
| 33 | + |
| 34 | + const activateCheats = () => { |
| 35 | + spModal.open({ |
| 36 | + size: 'sm', |
| 37 | + title: 'Cheats activated', |
| 38 | + message: 'Konami code entered', |
| 39 | + buttons: [{ label: '${Close}', cancel: true }] |
| 40 | + }); |
| 41 | + }; |
| 42 | + |
| 43 | + document.addEventListener('keydown', handleKeyPress); |
| 44 | + |
| 45 | + // Cleanup listener when widget is destroyed |
| 46 | + c.$onDestroy = function() { |
| 47 | + document.removeEventListener('keydown', handleKeyPress); |
| 48 | + clearTimeout(timeoutId); |
| 49 | + }; |
| 50 | +} |
0 commit comments