Scam3r / Удалённые сообщения

// ==UserScript==
// @name         Удалённые сообщения
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  VK Testers
// @match        https://*.vk.com/*
// @copyright 2019, vk.com/scam3r
// @license MIT
// ==/UserScript==

/* global geByClass1 */

function showDeletedMessages() {
  var flagDelete = 1 << 7;
  var typeUpdateFlag = 2;
  XMLHttpRequest.prototype.send = (function buildFakeSend(sendOrg) {
    return function fakeSend(...sendArgs) {
      var self = this;

      self.onreadystatechange = (function buildFakeOnChang(changeOrg) {
        if (!changeOrg) return;

        return function fakeOnReadyStateChange(...changeArgs) {
          var isLongPoll = (/^https:\/\/.?im(v4)?\.vk\.com\/.?im\d+/.test(self.responseURL));
          var isReady = (self.readyState == 4);

          if (isLongPoll && isReady && self.responseText) {
            try {
              let newJson = JSON.parse(self.responseText);
              newJson.updates.forEach((update) => {
                var isDelete = (update[0] == typeUpdateFlag && update[2] & flagDelete);
                if (isDelete) {
                  var el = geByClass1('_im_mess_' + update[1]);
                  if (el) {
                    var newEl = el.cloneNode(true);
                    el.style.opacity = 0.5;
                    el.parentElement.insertBefore(newEl, el);
                  }
                }

                return !isDelete;
              });
            }
            catch (e) {}
          }

          return changeOrg.apply(self, changeArgs);
        };
      })(self.onreadystatechange);

      return sendOrg.apply(self, sendArgs);
    };
  })(XMLHttpRequest.prototype.send);
}

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