fix edx

Fixing UX problems of Edx

当前为 2016-10-17 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         fix edx
// @namespace    http://tampermonkey.net/
// @version      0.5
// @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.includes('"height"') && e.data.includes('"index"')) {
            var message = JSON.parse(e.data);
            var height = message.height;
            var index = message.index;

            //console.log("READ " + e.data);

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

                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 currentFrame = window;

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

        var index = 0;
        for (var i = 0; i < parent.frames.length; i++) {
            if (parent.frames[i] === currentFrame) {
                index = i;
                break;
            }
        }

        var message = {"index": index, "height": height};
        var jsonMessage = JSON.stringify(message);
        //console.log("WRITE " + jsonMessage);
        window.parent.postMessage(jsonMessage, "https://courses.edx.org/");
    });

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