LearningApps Show Crossword Answers

Add "Show answers" button to LearningApps crossword

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         LearningApps Show Crossword Answers
// @version      0.1
// @description  Add "Show answers" button to LearningApps crossword
// @author       stennen
// @match        *://learningapps.org/display?v=*
// @grant        none
// @namespace    http://tampermonkey.net/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=learningapps.org
// @license      MIT
// ==/UserScript==

(function() {
    setTimeout(() => {
        function handler2() {

            let appcnt = document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")[0].contentWindow;

            if (!appcnt.eval('AppClient')) {
                return;
            }

            if (!appcnt.document.body.innerHTML.includes('<script type="text/javascript" src="crossword.js"></script>')) {
                return;
            }

            let dc = document.getElementById("content_container");
            let cntr = document.createElement("center");
            let el = document.createElement("button");
            el.setAttribute("id", "showAnswersBtn");
            el.innerText='Show Answers';
            el.style.fontFamily='Arial';
            el.style.fontSize='30px';
            el.style.textAlign='center';
            cntr.appendChild(el);
            dc.appendChild(cntr);
            el = document.getElementById("showAnswersBtn");
            el.onclick = () => {
                let appClient = document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")[0].contentWindow.eval('AppClient');

                let answers='';
                for (let i=0;i<50;i++) {
                    let answr = appClient.getParameter("word" + i);
                    if (answr) {
                        answers+='<h3>Word ' + i + ': ' + answr + '</h3>';
                    }
                }

                let wnd = window.open("about:blank");
                wnd.document.body.innerHTML = '<style>h1,h2,h3,h4,h5,h6{font-family:Arial}</style><center><h1>Answers</h1><hr>' + answers + '<hr><p>made by stennen</p></center>'
            };
        }

        if (document.getElementById("showAnswersBtn")) {
            return;
        }

        if (!document.body.getElementsByTagName("iframe")) {
            return;
        }


        if (!document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")) {
            return;
        }

        handler2();

    }, 1500);

    /* made by Stennen */
})();