fix edx

try to take over the world!

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

  1. // ==UserScript==
  2. // @name fix edx
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://courses.edx.org/*
  8. // @match https://inginious-lti.info.ucl.ac.be/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. if (window.top === window.self) {
  13.  
  14. window.onmessage = function(e){
  15. if (e.data.startsWith("height: ")) {
  16. var height = e.data.substring("height: ".length);
  17.  
  18. console.log("READ height: " + height);
  19.  
  20. if (height > 0) {
  21. var iframe = document.getElementsByTagName('iframe')[0];
  22.  
  23. console.log("scroll height: " + iframe.scrollHeight);
  24.  
  25. var currentHeight = iframe.offsetHeight;
  26.  
  27. var heightDiff = Math.abs(height - currentHeight);
  28.  
  29. if ((heightDiff > 2) || (currentHeight == 800)){
  30. iframe.style.height = height + "px";
  31. }
  32. }
  33. }
  34. };
  35.  
  36.  
  37. } else {
  38. MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  39.  
  40. var observer = new MutationObserver(function(mutations, observer) {
  41. var height = document.body.offsetHeight;
  42.  
  43. console.log("WRITE height: " + height);
  44. window.parent.postMessage("height: " + height , "https://courses.edx.org/");
  45. });
  46.  
  47. observer.observe(document, {
  48. subtree: true,
  49. childList: true
  50. });
  51. }