Skip to content

Instantly share code, notes, and snippets.

@koreapyj
Created November 14, 2022 19:44
Show Gist options
  • Save koreapyj/4388c4e4004bebcc3d3a3fa1989cdcc8 to your computer and use it in GitHub Desktop.
Save koreapyj/4388c4e4004bebcc3d3a3fa1989cdcc8 to your computer and use it in GitHub Desktop.
nProtect 비밀번호 키보드 입력
// ==UserScript==
// @name nProtect Physical Keyboard
// @namespace https://koreapyj.dcmys.kr/
// @version 0.1
// @description Your mother
// @author koreapyj
// @match https://*.hyundaicard.com/*
// @match https://*.samsungcard.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nprotect.com
// @grant none
// ==/UserScript==
(async function() {
'use strict';
const SPECIAL_CHARS_MAP = {
"느낌표":"!",
"골뱅이":"@",
"우물표시":"#",
"달러표시":"$",
"별표":"*",
"윗꺽쇠":"^",
"소괄호열기":"(",
"소괄호닫기":")",
"퍼센트":"%",
"앰퍼센드":"&",
"빼기표시":"-",
"밑줄":"_",
"같음표":"=",
"더하기표시":"+",
"역슬래시":"\\",
"수직바":"|",
"중괄호열기":"{",
"중괄호닫기":"}",
"대괄호열기":"[",
"대괄호닫기":"]",
"반쌍점":";",
"쌍점":":",
"작은따옴표":"'",
"큰따옴표":"\"",
"쉼표":",",
"마침표":".",
"거듭인용표열기":"<",
"거듭인용표닫기":">",
"물결표시":"~",
"강세표":"`",
"빗금":"/",
"물음표":"?",
"확인":"Enter",
"한개지움":"Backspace",
}
const usleep = (ms) => new Promise(r=>setTimeout(r,ms))
const __confirm = window.confirm
window.confirm = (message, ...args) => {
if(message.match(/^보안프로그램을 설치하셔야/)) return false
return __confirm.call(this, message, ...args)
}
document.addEventListener('keydown', async (e) => {
const pinpad = document.querySelector('#mobile-pinpad > *')?.parentNode
const keypad = Array.from(document.querySelectorAll('.nppfs-keypad')).find(x=>x.style.display!='none')
/* PIN 키보드 */
if(pinpad) {
const buttons = Array.from(pinpad.querySelectorAll('.pinpad-number')).reduce((obj, elem) => {
obj[~~elem.textContent] = elem
return obj
}, new Array(10))
const {key} = e
buttons[key].dispatchEvent(new MouseEvent('mousedown'))
}
/* 비밀번호 키보드 */
if(keypad) {
const buttons = Array.from(keypad.querySelectorAll('.kpd-data, .kpd-cmd')).reduce((obj, elem) => {
const key = elem.getAttribute('aria-label').replace(/^[소대]문자\s*/,'')
obj[key.match(/[A-Za-z0-9]/)?key:SPECIAL_CHARS_MAP[key] || key] = elem
return obj
}, {})
const {key, shiftKey, ctrlKey, altKey} = e
if(altKey) return
if(ctrlKey) {
if(key.toLowerCase() == 'v') {
const str = await navigator.clipboard.readText()
for(const char of str.split('')) {
buttons[char].dispatchEvent(new MouseEvent('click'))
await usleep(10)
}
}
return
}
if(!buttons[key]) {
console.log(e)
throw new TypeError('no key found')
}
buttons[key].dispatchEvent(new MouseEvent('click'))
}
})
const autocompleted_password_fields = Array.from(document.querySelectorAll('input[type="password"][data-keypad-type="alpha"]')).filter(x=>x.value)
if(autocompleted_password_fields.length == 1) {
const current_value = autocompleted_password_fields.value
autocompleted_password_fields.focus()
await usleep(100)
for(const char of current_value.split('')) {
document.dispatchEvent(new KeyboardEvent('keydown', {'key':char}))
await usleep(100)
}
document.dispatchEvent(new KeyboardEvent('keydown', {'key':'Enter'}))
console.log('autocomplete fixed')
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment