Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
6,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Edgenuity Toolkit
  3. // @namespace
  4. // @version      0.9
  5. // @description  Makes edgenuity better.
  6. // @author       Ryan
  7. // @match        https://r10.core.learn.edgenuity.com/Player/
  8. // @grant        all
  9. // ==/UserScript==
  10.  
  11. //---------------| Settings |--------------------
  12. var autofillVocab          = false; //Fill the vocabulary for you.
  13. var autoContinue           = false; //Automatically move to the next slide or section.
  14. var continueOnComplete     = false; //Continue when the currently playing video finishes rather than when available.
  15. var clickWhileTalking      = false; //Enables the ability to click while the speaker is talking
  16. var autoAnswer             = false; //Automatically hits submit button for assignments to get to the answer faster.
  17. var showInvisible          = false; //Set all objects visible.
  18. var settingsMenuVisible    = true;  //Show the floating settings menu in edgenuity.
  19. //=================DELAYS========================
  20. var vocabDelay             = 700;
  21. var autoContinueDelay      = 1000;
  22. var clickWhileTalkingDelay = 700;
  23. var randomAnswersDelay     = 1000;
  24. var showInvisibleDelay     = 1000;
  25. var continueOnCompleteDelay= 1000;
  26. //================Button Colours=================
  27. var clrDisabled            = "black";
  28. var clrEnabled             = "orange";
  29. var clrHover               = "purple";
  30. //-----------------------------------------------
  31.  
  32. var vocabTimer, continueTimer, cwtTimer, randomAnswersTimer,
  33.     showInvisibleTimer, continueOnCompleteTimer;
  34.  
  35. var divSettings, divContainer;
  36.  
  37. var btnHide, btnToggleVocab, btnToggleContinue, btnToggleCWT,
  38.     btnAutoAnswer, btnShowInvis, btnTranscript, btnContinueOnComplete;
  39.  
  40. var divSettingsHidden = false;
  41.  
  42.  
  43. function createSettingsMenu() {
  44.     console.log("Creating settings");
  45.     divSettings           = document.createElement("div");
  46.     divContainer          = document.createElement("div");
  47.     btnToggleVocab        = document.createElement("button");
  48.     btnToggleContinue     = document.createElement("button");
  49.     btnToggleCWT          = document.createElement("button");
  50.     btnAutoAnswer         = document.createElement("button");
  51.     btnShowInvisible      = document.createElement("button");
  52.     btnTranscript         = document.createElement("button");
  53.     btnContinueOnComplete = document.createElement("button");
  54.     btnHide               = document.createElement("button");
  55.  
  56.     var updateButtons = function() {
  57.         btnHide.style.backgroundColor           = divSettingsHidden ? clrEnabled : clrDisabled;
  58.         btnHide.style.color                     = "white";
  59.         btnHide.style.width                     = "100%";
  60.         divSettings.style.opacity               = divSettingsHidden ? "0.03"   : "0.7";
  61.         btnHide.innerHTML                       = divSettingsHidden ? "[+]"  : "[-]";
  62.         btnToggleVocab.style.backgroundColor    = autofillVocab     ? clrEnabled : clrDisabled;
  63.         btnToggleVocab.innerHTML                = "AutoVocab";
  64.         btnToggleContinue.style.backgroundColor = autoContinue      ? clrEnabled : clrDisabled;
  65.         btnToggleContinue.innerHTML             = "AutoContinue";
  66.         btnToggleCWT.style.backgroundColor      = clickWhileTalking ? clrEnabled : clrDisabled;
  67.         btnToggleCWT.innerHTML                  = "Enable clicking";
  68.         btnAutoAnswer.style.backgroundColor     = autoAnswer ? clrEnabled : clrDisabled;
  69.         btnAutoAnswer.innerHTML                 = "Auto Answer";
  70.         btnShowInvisible.style.backgroundColor  = showInvisible ? clrEnabled : clrDisabled;
  71.         btnShowInvisible.innerHTML              = "Show invisible";
  72.         btnTranscript.style.backgroundColor     = clrDisabled;
  73.         btnTranscript.innerHTML                 = "Parse Transcript";
  74.         btnContinueOnComplete.style.backgroundColor = continueOnComplete ? clrEnabled : clrDisabled;
  75.         btnContinueOnComplete.innerHTML         = "next when ready";
  76.     };
  77.     updateButtons();
  78.     divSettings.style.backgroundColor       = "white";
  79.     divSettings.style.width                 = "120px";
  80.     divSettings.style.height                = "auto";
  81.     divSettings.style.zIndex                = "100";
  82.     divSettings.style.position              = "absolute";
  83.     divSettings.style.top                   = "50px";
  84.     divSettings.style.left                  = "50%";
  85.     divSettings.style.paddingTop             = "15px";
  86.     $(divSettings).draggable();
  87.  
  88.     btnHide.addEventListener("click", function() {
  89.         if ( divSettingsHidden ) {
  90.             divContainer.style.display = "block";
  91.             divSettingsHidden = false;
  92.         } else {
  93.             divContainer.style.display = "none";
  94.             divSettingsHidden = true;
  95.         }
  96.         updateButtons();
  97.     });
  98.     btnToggleVocab.addEventListener("click", function() {
  99.         if ( autofillVocab ) {
  100.             autofillVocab = false;
  101.             clearInterval(vocabTimer);
  102.         } else {
  103.             autofillVocab = true;
  104.             clearInterval(vocabTimer);
  105.             vocabLoop();
  106.         }
  107.         updateButtons();
  108.     });
  109.     btnToggleContinue.addEventListener("click", function() {
  110.         if ( autoContinue ) {
  111.             autoContinue = false;
  112.             clearInterval(continueTimer);
  113.         } else {
  114.             autoContinue = true;
  115.             continueTimer = setInterval(goNext, autoContinueDelay);
  116.         }
  117.         updateButtons();
  118.     });
  119.     btnContinueOnComplete.addEventListener("click", function() {
  120.        if ( continueOnComplete ) {
  121.            continueOnComplete = false;
  122.            clearInterval(continueOnCompleteTimer);
  123.        } else {
  124.            continueOnComplete = true;
  125.            continueOnCompleteTimer = setInterval(continueWhenReady, continueOnCompleteDelay);
  126.        }
  127.     });
  128.     btnToggleCWT.addEventListener("click", function() {
  129.         if ( clickWhileTalking ) {
  130.             clearInterval(cwtTimer);
  131.             clickWhileTalking = false;
  132.         } else {
  133.             clickWhileTalking = true;
  134.             cwtTimer = setInterval(enableClicking, clickWhileTalkingDelay);
  135.         }
  136.         updateButtons();
  137.     });
  138.     btnAutoAnswer.addEventListener("click", function() {
  139.         if ( autoAnswer ) {
  140.             autoAnswer = false;
  141.             clearInterval(randomAnswersTimer);
  142.         } else {
  143.             autoAnswer = true;
  144.             randomAnswersTimer = setInterval(setAnswers, randomAnswersDelay);
  145.         }
  146.         updateButtons();
  147.     });
  148.     btnShowInvisible.addEventListener("click", function() {
  149.         if ( showInvisible ) {
  150.             showInvisible = false;
  151.             clearInterval(showInvisibleTimer);
  152.             hideInvisibleItems();
  153.         } else {
  154.             showInvisible = true;
  155.             showInvisibleTimer = setInterval(showInvisibleItems, showInvisibleDelay);
  156.         }
  157.         updateButtons();
  158.     });
  159.     btnTranscript.addEventListener("click", function() {
  160.         var textContent = parseTranscript();
  161.         if ( textContent !== "" ) {
  162.             var div = $(document.createElement('div'))
  163.             .css("max-width", "700px")
  164.             .css("height", "auto")
  165.             .css("position", "absolute")
  166.             .css("top",  $(divSettings).position().top+100+"px")
  167.             .css("left", $(divSettings).position().left+100+"px")
  168.             .css("z-index", "1000")
  169.             .css("background-color", "black")
  170.             .css("padding", "20px")
  171.             .append(
  172.                 $(document.createElement('button'))
  173.                 .html("close")
  174.                 .on("click", function() {
  175.                     div.remove();
  176.                 })
  177.             )
  178.             .draggable();
  179.             var textArea = $(document.createElement("textarea"))
  180.             .css("height", "200px")
  181.             .css("width", "100%")
  182.             .css("resize", "both")
  183.             .val(textContent)
  184.             .on("click", function() {
  185.                 $(this).select();
  186.             });
  187.             div.append(textArea);
  188.             $(document.body).append(div);
  189.         }
  190.     });
  191.     divContainer.appendChild(btnToggleVocab);
  192.     divContainer.appendChild(btnToggleContinue);
  193.     divContainer.appendChild(btnContinueOnComplete);
  194.     divContainer.appendChild(btnToggleCWT);
  195.     divContainer.appendChild(btnAutoAnswer);
  196.     divContainer.appendChild(btnShowInvisible);
  197.     divContainer.appendChild(btnTranscript);
  198.     //Transitioned to using jquery here
  199.     $(divContainer).append(
  200.         $(document.createElement('button')).
  201.         html("Paint it black")
  202.         .css("background-color", clrDisabled)
  203.         .on("click", function() {
  204.             $("*").not($(divSettings))
  205.                 .css("background-color", "black")
  206.                 .css("color", "white");
  207.         })
  208.     );
  209.     $(divContainer).append(
  210.         $(document.createElement('button')).
  211.         html("Notepad")
  212.         .css("background-color", clrDisabled)
  213.         .on("click", function() {
  214.             var div = $(document.createElement('div'))
  215.             .css("width", "auto")
  216.             .css("height", "auto")
  217.             .css("position", "absolute")
  218.             .css("top",  $(divSettings).position().top+100+"px")
  219.             .css("left", $(divSettings).position().left+100+"px")
  220.             .css("z-index", "1000")
  221.             .css("background-color", "black")
  222.             .css("padding", "20px")
  223.             .append(
  224.                 $(document.createElement('button'))
  225.                 .html("close")
  226.                 .css("display", "block")
  227.                 .on("click", function() {
  228.                     div.remove();
  229.                 })
  230.             )
  231.             .draggable();
  232.             var textArea = $(document.createElement("textarea"))
  233.             .css("min-height", "30px")
  234.             .css("resize", "both")
  235.             .css("display", "block");
  236.             div.append(textArea);
  237.             $(document.body).append(div);
  238.         })
  239.     );
  240.  
  241.     for ( var i=0; i < divContainer.childNodes.length; i++) {
  242.         var n = divContainer.childNodes[i];
  243.         n.style.width        = "100%";
  244.         n.style.fontSize     = "13px";
  245.         n.style.border       = "none";
  246.         n.style.borderRadius = "1px";
  247.         n.style.color        = "white";
  248.         $(n).hover(function() {
  249.             $(this).css("background-color", clrHover)
  250.                 .css("color", "white");
  251.         }, function() {
  252.             $(this).css("background-color", clrDisabled);
  253.             updateButtons();
  254.         });
  255.     }
  256.     divSettings.appendChild(btnHide);
  257.     divSettings.appendChild(divContainer);
  258.     document.body.appendChild(divSettings);
  259. }
  260.  
  261. function vocabLoop() {
  262.     try {
  263.         vocabTimer = setInterval(scanVocab, vocabDelay);
  264.     } catch (err) {
  265.         console.log(err);
  266.     }
  267. }
  268.  
  269. function scanVocab() {
  270.     var stage = document.getElementById("stageFrame");
  271.     var frame;
  272.     if ( stage ) {
  273.         frame = stage.contentWindow.document;
  274.     } else {
  275.         return;
  276.     }
  277.     var vocabButton = stage.contentWindow.document.getElementsByClassName("plainbtn alt selected")[0];
  278.     if ( vocabButton ) {
  279.         var vocabInput = frame.getElementsByClassName("word-textbox word-normal")[0];
  280.         if ( vocabInput ) {
  281.             vocabInput.value = vocabButton.innerHTML;
  282.             var playbutton = frame.getElementsByClassName("playbutton vocab-play")[0];
  283.             if ( playbutton ) {
  284.                 playbutton.click();
  285.             }
  286.             var nextButton = frame.getElementsByClassName("uibtn-arrow-next")[0];
  287.             if ( nextButton ) {
  288.                 nextButton.click();
  289.             }
  290.         }
  291.     }
  292. }
  293.  
  294.  
  295. function continueWhenReady() {
  296.     var frame = document.getElementById("stageFrame");
  297.     if ( frame ) {
  298.         frame = frame.contentWindow.document;
  299.         var currentTime = document.getElementsByClassName("uid1_time")[0];
  300.         if ( currentTime ) {
  301.             currentTime = currentTime.innerHTML.split(" / ");
  302.             if ((currentTime[0] && currentTime[1]) && currentTime[0] == currentTime[1]) {
  303.                 goNext();
  304.             }
  305.         }
  306.     }
  307. }
  308.  
  309.  
  310. function goNext() {
  311.     var footnavRight = document.getElementsByClassName("footnav goRight")[0];
  312.     if ( footnavRight ) {
  313.         footnavRight.click();
  314.     }
  315.     var frame = document.getElementById("stageFrame");
  316.     if ( frame ) {
  317.         frame = frame.contentWindow.document;
  318.         var goRight = frame.getElementsByClassName("FrameRight")[0];
  319.         if ( goRight ) {
  320.             var b = goRight.firstChild;
  321.             if ( b ) {
  322.                 b.click();
  323.             }
  324.         }
  325.     }
  326. }
  327.  
  328. function enableClicking() {
  329.     var frame = document.getElementById("stageFrame");
  330.     if ( frame ) {
  331.         var invisodiv = frame.contentWindow.document.getElementById("invis-o-div");
  332.         if ( invisodiv ) {
  333.             //invisodiv.style.backgroundColor  = "#00ff00";
  334.             //invisodiv.style.opacity          = "0.3";
  335.             //invisodiv.style.pointerEvents    = "none";
  336.             invisodiv.parentNode.removeChild(invisodiv);
  337.         }
  338.         var submitBlocker = frame.contentWindow.document.getElementById("submitBlocker");
  339.         if ( submitBlocker ) {
  340.             submitBlocker.parentNode.removeChild(submitBlocker);
  341.         }
  342.         var submitLoading = frame.contentWindow.document.getElementById("submitLoading");
  343.         if ( submitLoading ) {
  344.             submitLoading.parentNode.removeChild(submitLoading);
  345.         }
  346.     }
  347. }
  348.  
  349. function setAnswers() {
  350.     var frame = document.getElementById("stageFrame");
  351.     if ( frame ) {
  352.         frame = frame.contentWindow.document;
  353.         var preview = frame.getElementById("iFramePreview");
  354.         if ( preview ) {
  355.             preview = preview.contentWindow.document;
  356.             var buttons = preview.getElementsByClassName("answer-choice-button");
  357.             for( var i=0; i < buttons.length; i++ ) {
  358.                 buttons[i].checked = true;
  359.             }
  360.             var submit = frame.getElementById("btnCheck");
  361.             if ( submit ) {
  362.                 submit.click();
  363.                 console.log(submit);
  364.             }
  365.         }
  366.     }
  367. }
  368.  
  369. function showInvisibleItems() {
  370.     var frame = document.getElementById("stageFrame");
  371.     if ( frame ) {
  372.         frame = frame.contentWindow.document;
  373.         $(frame.body).find("*:hidden").not(".uibtn")
  374.             .show()
  375.             .addClass("sethidden");
  376.     }
  377. }
  378.  
  379. function hideInvisibleItems() {
  380.     var frame = document.getElementById("stageFrame");
  381.     if ( frame ) {
  382.         frame = frame.contentWindow.document;
  383.         $(frame.body).find(".sethidden").hide();
  384.     }
  385. }
  386.  
  387. function parseTranscript() {
  388.     var transcripts = document.getElementsByClassName("transcript-text");
  389.     var total = "";
  390.     for ( var i=0; i < transcripts.length; i++ ) {
  391.         total += transcripts[i].innerHTML.trim()
  392.             .replace(/( )+/g, " ")
  393.             .replace("TEACHER: ", "\n\nTEACHER:\n") +
  394.             " ";
  395.     }
  396.     return total;
  397. }
  398.  
  399.  
  400. (function() {
  401.     'use strict';
  402.     //Generate Settings Menu
  403.     if ( settingsMenuVisible ) {
  404.         createSettingsMenu();
  405.     }
  406.     //VOCAB
  407.     if ( autofillVocab ) {
  408.         vocabLoop();
  409.     }
  410.     //autocontinue
  411.     if ( autoContinue ) {
  412.         continueTimer = setInterval(goNext, autoContinueDelay);
  413.     }
  414.     //click while talking
  415.     if ( clickWhileTalking ) {
  416.         cwtTimer = setInterval(enableClicking, clickWhileTalkingDelay);
  417.     }
  418.     //autoAnswer
  419.     if ( autoAnswer ) {
  420.         randomAnswersTimer = setInterval(setAnswers, randomAnswersDelay);
  421.     }
  422.     //show Invisible
  423.     if ( showInvisible ) {
  424.         showInvisibleTimer = setInterval(showInvisibleItems, showInvisibleDelay);
  425.     }
  426. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement