/*
* @title KeyLogger
* @description Simple Key Logger (w/o modifiers, composition)
* @include http://*
* @license MIT License
* @javascript_url
*/
(() => {
if (window.__KeyLogger_finish) {
window.__KeyLogger_finish();
return;
}
let events = [];
const listener = e => {
if (e.isComposing || ['Control','Shift','Alt','Meta'].includes(e.key)) return;
const ts = new Date().toLocaleString('ja-JP', { hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' });
const shortStr = [e.ctrlKey && 'Ctrl', e.shiftKey && 'Shift', e.altKey && 'Alt', e.metaKey && 'Meta', e.key].filter(x => x).join('+');
events.push([ts, shortStr, `(code=${e.code},keyCode=${e.keyCode})`].join('\t'));
};
window.addEventListener('keydown', listener, { capture: true });
window.__KeyLogger_finish = () => {
window.removeEventListener('keydown', listener, { capture: true });
Object.assign(window.open().document.body, { textContent: `---- 押されたキー ----\n${events.join('\n')}\n---- 環境情報 ----\nURL: ${location.href}\n環境: ${navigator.userAgent}`, style: "white-space: pre" });
delete window.__KeyLogger_finish;
};
})();