MS Whiteboard Optimizer

Optimize performance of MS Whiteboard with a lot of content

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MS Whiteboard Optimizer
// @namespace    https://i.zapic.moe/
// @version      0.1
// @description  Optimize performance of MS Whiteboard with a lot of content
// @author       KawaiiZapic
// @match        https://whiteboard.office.com/me/whiteboards/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=office.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const debounceList = {};
    const debounce = (name,cb, time) => {
        const result = debounceList[name] > 0;
        result && clearTimeout(debounceList[name]);
        debounceList[name] = setTimeout(() => {
            debounceList[name] = -1;
            cb();
        }, time);
        return result;
    }
    const getGrandparent = $ => $.parentElement.parentElement;
    const io = new IntersectionObserver((entries) => {
         entries.forEach((entry) => {
             const grand = getGrandparent(entry.target);
             if (entry.intersectionRatio > 0) {
                 grand.style.visibility = ""
                 grand.style.display = ""
             } else {
                 grand.style.visibility = "hidden"
             }
         });
    });
    setInterval(() => {
        const canvasContent = document.querySelector('#canvasContent');
        if (!canvasContent || canvasContent.__attached) return;
        canvasContent.__attached = true;
        const observerOptions = {
            childList: true,
            attributes: false,
            subtree: false
        }
        const observer = new MutationObserver(() => {
           debounce("mutation", () => {
               canvasContent.querySelectorAll("svg.inkGroup").forEach(v => {
                   if (v.__observerd) return;
                   v.__observerd = true;
                   io.observe(v);
               });
           }, 1000)
        });
        observer.observe(canvasContent, observerOptions);
        const attrObserver = new MutationObserver(() => {
            if (!debounce("attribute", () => {
                console.log("drag end");
                canvasContent.querySelectorAll("svg.inkGroup").forEach(v => {
                    const grand = getGrandparent(v);
                    if (grand.style.visibility == "hidden") {
                        grand.style.display = "none";
                    }
                });
            },1000)) {
                console.log("drag start");
                canvasContent.querySelectorAll("svg.inkGroup").forEach(v => {
                    const grand = getGrandparent(v);
                    if (grand.style.display == "none") {
                        grand.style.visibility = "hidden";
                        grand.style.display = "";
                    }
                });
            }
        });
        const transformComponent = document.querySelector(".transformComponent");
        attrObserver.observe(transformComponent, {
            childList: false,
            attributes: true,
            subtree: false
        });
        console.log("[MWF] MO attached.");
    }, 1000);
})();