Key Sequence Detection


Posted by wayne201299 on 2023-09-28

為網站添加secret code,輸入後會有小彩蛋

  1. 監聽鍵盤點擊事件
  2. 將點擊的案件推入計算陣列後比對
    const pressed = [];
     const secretcode = 'alan'
     window.addEventListener("keyup", (e) => {
       pressed.push(e.key);
       pressed.splice(-secretcode.length - 1, pressed.length - secretcode.length);
       if (pressed.join('').includes(secretcode)) {
         cornify_add();
       }
     })
    

Konami Code
在前端開發中,Konami Code 通常指的是以下按鍵序列:
上箭頭、上箭頭、下箭頭、下箭頭、左箭頭、右箭頭、左箭頭、右箭頭、B 鍵、A 鍵、Enter(或 Return)鍵


#javascript #html







Related Posts

DAY11:Disemvowel Trolls

DAY11:Disemvowel Trolls

F2E合作社|modal燈箱效果|Bootstrap 5網頁框架開發入門

F2E合作社|modal燈箱效果|Bootstrap 5網頁框架開發入門

DAY34:Product of consecutive Fib numbers

DAY34:Product of consecutive Fib numbers


Comments