Microsoft Teams - Keep Active / Available

Keeps you active between the hours specified in the script

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Microsoft Teams - Keep Active / Available
// @description Keeps you active between the hours specified in the script
// @namespace   Violentmonkey Scripts
// @match       *://*.teams.microsoft.com/_*
// @grant       none
// @version     1.04
// @author      -
// @run-at       document-idle
// @license AGPL
// ==/UserScript==

var startTime =  9 * 60 + 0; // Work starts at 9am
var endTime   = 17 * 60 + 0; // Work ends at 5pm

function inTime() {
    var now = new Date();
    var time = now.getHours() * 60 + now.getMinutes();
    return time >= startTime && time < endTime;
}

(function(sendParam) {
  XMLHttpRequest.prototype.send = function() {
      if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
        try {
            let jsonMsg = JSON.parse(arguments[0]);
            if (jsonMsg.isActive != null) {
              if (jsonMsg.isActive === false) {
                if(inTime()) {
                  jsonMsg.isActive = true;
                  arguments[0] = JSON.stringify(jsonMsg);
                }
              }
            }
        } catch (e) {
          console.error('Teams - Always Online', e);
        }
      }

      sendParam.apply(this, arguments);
  };
})(XMLHttpRequest.prototype.send);