No Afk Disconnect

Prevents you from disconnecting when away from the tab

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         No Afk Disconnect
// @version      1.1.0
// @description  Prevents you from disconnecting when away from the tab
// @namespace    Can't restore? Can't disconnect
// @author       ABC
// 
// @match        https://arras.io/
// @match        https://arras.netlify.app/
// @run-at       document-start
// @grant        none
// 
// @require https://greasyfork.org/scripts/434599-apm/code/APM.js?version=983252
// ==/UserScript==

arras.hijack().then(socket => {
  const worker = new Worker(URL.createObjectURL(new Blob([`
setInterval(() => {
  postMessage(1);
}, 1000);
`])));
  
  let lastDX = 0,
      lastDY = 0,
      lastFlags = 0;
  let sendingArtificial = false;
  
  socket.hookSend(p => {
    if (p[0] === 'C' && !sendingArtificial) {
      lastDX = p[1];
      lastDY = p[2];
      lastFlags = p[3];
    }
  });
  
  worker.onmessage = () => {
    sendingArtificial = true;
    socket.talk('C', lastDX + (Math.random() < .5 ? 0 : 1), lastDY + (Math.random() < .5 ? 0 : 1), lastFlags);
    sendingArtificial = false;
  }
})