Raw Source
flyink13 / vk.com Swipe im reply

// ==UserScript==
// @name         vk.com Swipe im reply
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Ответ на сообщение по свайпу
// @author       Flyink13
// @match        https://*.vk.com/*
// @updateURL https://openuserjs.org/meta/flyink13/Web_Sticker_Keywords.meta.js
// @copyright 2018, flyink13 (https://openuserjs.org/users/flyink13)
// @license MIT
// ==/UserScript==
/* global addEvent, each, gpeByClass */

function addReplyWheelEvent() {
    if (typeof addEvent != 'function') return;
    if (typeof each != 'function') return;
    if (typeof gpeByClass != 'function') return;

    var wheelMessages = [];
    addEvent(window, 'mousemove click scroll', function(e) {
        each(wheelMessages, function() {
            this.style.transform = '';
            delete this.deltaX;
        });
    });
    addEvent(window, 'wheel', function(e) {
        var msg = gpeByClass('im-mess', e.target);
        var mid = wheelMessages.indexOf(msg);
        var rep = document.querySelector('.im-page--chat-input .im-replied');
        if (!msg || rep || msg.deltaY) return;
        if (Math.abs(e.deltaY) > 3 || (Math.abs(e.deltaX) < 2 && msg.deltaX < 5)) return;
        msg.deltaX = msg.deltaX ? msg.deltaX + e.deltaX : 1;
        msg.deltaX = Math.max(msg.deltaX, 0);
        msg.style.transform = 'translateX(' + (-msg.deltaX) + 'px)';
        if (mid == -1) mid = wheelMessages.push(msg);

        if (msg.deltaY || msg.deltaX < 50) return;
        wheelMessages.splice(mid, 1);
        msg.style.transform = '';
        delete msg.deltaX;
        msg.click();
        document.querySelector('[data-action="respond"]').click();
    });
}

(function injectScript() {
    var script = document.createElement('script');
    script.appendChild(document.createTextNode('(' + addReplyWheelEvent + ')();'));
    (document.body || document.head || document.documentElement).appendChild(script);
})();