fix edx

Fixing UX problems of Edx

目前為 2016-10-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         fix edx
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Fixing UX problems of Edx
// @author       Yaroslav Shepilov
// @match        https://courses.edx.org/*
// @match        https://inginious-lti.info.ucl.ac.be/*
// @grant        none
// ==/UserScript==

if (window.top === window.self) {

    window.onmessage = function(e){
        if (e.data.startsWith("height: ")) {
            var height = e.data.substring("height: ".length);

            //console.log("READ height: " + height);

            if (height > 0) {
                var iframe = document.getElementsByTagName('iframe')[0];

                var currentHeight = iframe.offsetHeight;

                var heightDiff = height - currentHeight;

                if ((heightDiff > 0) || (currentHeight == 800) || (heightDiff < -50)) {
                    iframe.style.height = height + "px";
                }
            }
        }
    };


} else {
    MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

    var observer = new MutationObserver(function(mutations, observer) {
        var height = document.body.offsetHeight;

        //console.log("WRITE height: " + height);
        window.parent.postMessage("height: " + height , "https://courses.edx.org/");
    });

    observer.observe(document, {
        subtree: true,
        childList: true
    });
}