うしブログ

うしブログ

趣味で運営する、GeoGebraの専門ブログ。

(作業メモ)StartPoint要検証(2行の場合;テキスト変更時未定義問題)

(要修復)ToggleButton・RollPolygonWithoutSlipping・貯金時計・直感力トレーニング

geogebra.org/classic でのエラーメッセージを横取りする

//web版GeoGebraのエラーダイヤログを出ないようにして、エラーメッセージのみを横取りする(console記録+テキストオブジェクトに書き出し)
// ggbOnInit関数内に、seizureErrorDialog(); を記述しておくとよい
// seizureErrorDialog(10);←10行分をテキストオブジェクトに記録
function seizureErrorDialog(maxRow) {
    ggbApplet.evalCommand("errorText=\"error log here.\"");

    // GeoGebraのエラーログ表示用オブジェクト(テキスト)の名前を指定
    var logTextName = "errorText";

    // 対象ノード
    const target = document.getElementsByTagName("main")[0];

    // インスタンス
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            console.log(mutation);
            if (mutation.addedNodes[0]) {
                if (mutation.addedNodes[0].className == "dialogComponent errorDialog") {
                    console.log(mutation.addedNodes[0]);
                    var errText = mutation.addedNodes[0].getElementsByClassName("mainPanel")[0].textContent;
                    var outputText = "[GeoGebra - エラー]" + errText;
                    console.log(outputText);
                    var currentLog = ggbApplet.getValueString(logTextName);
                    if (maxRow && currentLog.split("\n").length >= maxRow) {
                        var tempArr = currentLog.split("\n");
                        tempArr.shift();
                        currentLog = tempArr.join("\n");
                    }
                    ggbApplet.setTextValue(logTextName, currentLog + "\n" + outputText);
                    mutation.addedNodes[0].getElementsByClassName("dialogContainedButton")[0].click();
                }
            }

        });
    });

    // オブザーバ
    const config = {
        childList: true,
        subtree: true
    };

    observer.observe(target, config);
}