VK: Hide Typing

look @name

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           VK: Hide Typing
// @name:ru        ВК: Скрыть набор текста
// @description    look @name
// @description:ru Смотри @name:ru
// @namespace      hidetyping.user.js
// @license        MIT
// @author         askornot
// @version        1.0.0
// @match          https://*.vk.com/*
// @compatible     chrome    Violentmonkey 2.12.7
// @compatible     firefox   Greasemonkey 4.11
// @compatible     firefox   Violentmonkey 2.12.14
// @compatible     firefox   Tampermonkey 4.12.6132
// @homepageURL    https://greasyfork.org/en/scripts/387887-vk-hide-typing
// @supportURL     https://greasyfork.org/en/scripts/387887-vk-hide-typing/feedback
// @noframes
// ==/UserScript==

'use strict';

const PROXY = {
  'vk.com': () => {
    const _XMLHttpRequest = XMLHttpRequest.prototype;
    _XMLHttpRequest.send = new Proxy(_XMLHttpRequest.send, {
      apply(target, thisArg, argumentsList) {
        const [ query ] = argumentsList;
        if (/typing|audiomessage/.test(query)) return null;
        return Reflect.apply(target, thisArg, argumentsList);
      },
    });
  },
  'm.vk.com': () => {
    const _fetch = window.fetch;
    window.fetch = (input, init = {}) => {
      const _input = input.clone();
      return input
        .formData()
        .then((x) => [...x.values()].includes('typing'))
        .then((isTyping) =>
          isTyping ? new Promise(() => null) : _fetch(_input, init)
        );
    };
  },
};

const { host } = location;

const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.textContent = `(${PROXY[host].toString()})()`;
document.head.append(script);