forked from MichaelAquilina/Whatsappium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
web_telegram_evgeny-nadymov_shortcuts.js
49 lines (41 loc) · 1.28 KB
/
web_telegram_evgeny-nadymov_shortcuts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
function isKeyCode(keyCode, char) {
const keyChar = String.fromCharCode(keyCode)
return keyChar == char || keyChar == char.toUpperCase()
}
const intervalId = setInterval(() => {
bindShortcuts()
}, 5000)
function bindShortcuts() {
console.log('bind shortcuts')
if (isTelegramPageReady()) {
clearInterval(intervalId)
}
window.removeEventListener('keyup', handleKeyUp)
window.addEventListener('keyup', handleKeyUp)
window.removeEventListener('click', handleReply)
window.addEventListener('click', handleReply)
}
async function handleReply(e) {
if (e.target.closest('.message') && e.altKey) {
await sleep(50)
document.querySelector('.header-command button:nth-child(3').click()
}
}
function isTelegramPageReady() {
const inputSearch = document.querySelector('.header-status-content')
if (inputSearch) return true
else return false
}
function handleKeyUp(e) {
console.log('Keyboard input new')
if (e.shiftKey) {
if (isKeyCode(e.keyCode, 'd')) {
e.preventDefault()
console.log('press shift + d')
document.querySelector('.media-viewer-footer div:nth-child(3)').click()
}
}
}