Skip to content

Instantly share code, notes, and snippets.

@sergiks
Last active June 9, 2017 12:44
Show Gist options
  • Save sergiks/db60bce96123671e1115923fbfb6f286 to your computer and use it in GitHub Desktop.
Save sergiks/db60bce96123671e1115923fbfb6f286 to your computer and use it in GitHub Desktop.
VK send message via browser console JS
/**
* Отправка ЛС во ВКонтакте скриптом из консоли браузера.
* Эксперимент для валидации идеи с Electron-приложением.
* Работает 2017-06-09 в Firefox 53.0.3 (64-bit) / Mac OS X 10.11.6
*
* Выполнять на странице диалога с нужным пользователем
* https://vk.com/im?sel=755074 цифры в конце это id пользователя ВК.
*
* by Sergei Sokolov, hello@sergeisokolov.com, 2017-06-09, Moscow.
*/
function sendMsg(txt) {
var el = document.querySelector('div.im_editable.im-chat-input--text._im_text');
el.innerText = txt;
el.dispatchEvent(new Event('focus'));
el.dispatchEvent(new Event('keydown'));
setTimeout( function(){
var btn = document.querySelector('button.im-send-btn.im-chat-input--send._im_send.im-send-btn_send');
console.log("btn:", btn);
if( btn) {
btn.dispatchEvent(new Event('click'));
} else {
console.log("no button");
}
}, 0);
}
sendMsg("ТЕстовое сообщение");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment