Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:
- /* School name */
- var schoolName;
- /* Dictionary defining unique schools along with optional predefines */
- var uniqueSchools = {
- "Straighterline": "See exam notes",
- "Western Governors University": "You will have EXAM_TIME to take your exam today. You're only allowed to use a dry erase board and a calculator. " +
- "You have 0 breaks during the exam. Do you understand these rules, and will you be using these materials?",
- "East Carolina University(UNC Online)": "See exam notes",
- "*Internet Testing Systems (ETS)*": "See exam notes",
- "*Carson, Dunlop & Associates LTD*": "See exam notes"
- };
- /* Exam name and exam time, in minutes */
- var examName;
- var examTime;
- /* If this test has breaks */
- var hasBreaks;
- /* If this test requires destruction of scratch paper */
- var destroyScratch;
- /* Exam confirmation message */
- var confirmation;
- /* Exam rules message */
- var rules;
- /* Exam resources message */
- var resources;
- /* Confirmation HTML */
- var confDesc = "<dt id='confDesc'>Confirmation</dt>";
- var confText = "<dd id='confText'> <a id='confCopyBtn' class='js-tooltip-copy text-cursor' title='Copy Confirmation' data-toggle='tooltip'><span class='fa fa-clipboard'> </span></a></dd>";
- /* Rules HTML */
- var rulesDesc = "<dt id='rulesDesc'>Rules</dt>";
- var rulesText = "<dd id='rulesText'> <a id='rulesCopyBtn' class='js-tooltip-copy text-cursor' title='Copy Rules' data-toggle='tooltip'><span class='fa fa-clipboard'> </span></a></dd>";
- /* Resources HTML */
- var resDesc = "<dt id='resDesc'>Resources</dt>";
- var resText = "<dd id='resText'> <a id='resCopyBtn' class='js-tooltip-copy text-cursor' title='Copy Resources' data-toggle='tooltip'><span class='fa fa-clipboard'> </span></a></dd>";
- /* Selects an element's text and copies it to the clipboard */
- function selectText(element) {
- var range, selection;
- var textNode = element.first().contents()[0];
- if (document.selection) {
- range = document.body.createTextRange();
- range.moveToElementText(confMessage);
- range.select();
- } else if (window.getSelection) {
- selection = window.getSelection();
- range = document.createRange();
- range.selectNodeContents(textNode);
- selection.removeAllRanges();
- selection.addRange(range);
- }
- document.execCommand("copy");
- selection.removeAllRanges();
- };
- /* Determines if a school is unique based on school name */
- function determineUniqueSchool(schoolName) {
- return schoolName in uniqueSchools;
- }
- /* Formats and returns the exam confirmation string */
- function getConfirmationString(examName) {
- examName = examName.replace("VIP", "");
- includeExam = examName.match(/exam|test/ig) ? "" : "exam";
- return `My notes say you\'re scheduled for your ${examName} ${includeExam} today. Is this correct?`;
- }
- /* Formats and returns the exam rules string */
- function getRulesString() {
- return `You will have ${examTime} to take your exam, with ${(hasBreaks ? "" : "no")} breaks allowed. Do you understand?`;
- }
- /* Formats and returns the exam resource string */
- /* todo: fix some plurality issues */
- function getResourceString(resourceList) {
- var resources = "For this exam, you are permitted ";
- var multipleResources = resourceList.length > 1;
- if (resourceList.length != 0) {
- /* pop last resource, add commas between resources, add last resource */
- lastResource = resourceList.pop();
- resourceList = resourceList.join(", ");
- if (multipleResources) {
- resourceList = "these materials: " + resourceList + ", and " + lastResource;
- } else {
- resourceList += lastResource;
- }
- if (destroyScratch) {
- resourceList += ". You will need to destroy your scratch paper at the end of the exam";
- }
- if (multipleResources) {
- resourceList += ". Will you be using these materials today?";
- } else {
- resourceList += ". Will you be using this today?";
- }
- resourceList = resourceList.replace(new RegExp('1 Sheet'), "1 Sheet of Scratch Paper");
- resourceList = resourceList.replace(new RegExp('sheets', 'gi'), "Sheets of Scratch Paper");
- resources += resourceList;
- } else {
- resources = "For this exam, you are not permitted any materials. Do you understand?";
- }
- return resources;
- }
- /* Find appropriate exam identifiers */
- /* todo: must be a better way to do this */
- $("dt").each(function(index) {
- var dt = $(this);
- var dd = dt.next();
- /* For exam windows with multiple days */
- /* Todo: make this work for more than 2 days */
- if (dd.next() != undefined && dd.next().is("dd")) {
- dd = dd.next();
- }
- var descriptorText = dt.text();
- var detailText = dd.text();
- switch (descriptorText) {
- case 'Institution':
- schoolName = detailText;
- break;
- case 'Exam Window':
- /* Add message elements to page */
- dd.after( confDesc +
- confText +
- rulesDesc +
- rulesText +
- resDesc +
- resText);
- break;
- case 'Exam Name':
- examName = detailText;
- break;
- case 'Exam Duration':
- examTime = detailText;
- break;
- }
- });
- /* attach copy functionality, define element variables */
- /* confirmation element and button */
- var confMessage = $('#confText');
- var confCopyBtn = $('#confCopyBtn');
- confCopyBtn.click(() => {
- selectText(confMessage);
- });
- /* rules element and button */
- var rulesMessage = $('#rulesText');
- var rulesCopyBtn = $('#rulesCopyBtn');
- rulesCopyBtn.click(() => {
- selectText(rulesMessage);
- });
- /* resources element and button */
- var resMessage = $('#resText');
- var resCopyBtn = $('#resCopyBtn');
- resCopyBtn.click(() => {
- selectText(resMessage);
- });
- /* get all permitted resources and breaks */
- var resourceListElement = $('h4:contains("Permitted Resources")').next();
- var resourceList = [];
- resourceListElement.each(function(index) {
- resourceList.push($(this).text());
- });
- /* list of resources initially includes non-string elements */
- resourceList = resourceList[0].split("\n").filter(String);
- /* bathroom breaks and scratch paper destruction are handled separately */
- resourceList = resourceList.filter(item => item !== "Bathroom breaks" && item !== "Destroy Scratch Paper");
- /* format resource list into string and set appropriate variables */
- /* unique schools have resources and exam times listed elsewhere */
- var isUniqueSchool = determineUniqueSchool(schoolName);
- if (isUniqueSchool) {
- resCopyBtn.remove();
- rules = uniqueSchools[schoolName].replace("EXAM_TIME", examTime);
- resources = "Unique school (Use Rules for rule confirmation and resource list)";
- } else {
- console.log(resourceList);
- hasBreaks = resourceList.includes("Bathroom breaks");
- destroyScratch = resourceList.includes("Destroy Scratch Paper");
- rules = getRulesString();
- resources = getResourceString(resourceList);
- }
- /* exam confirmation should be the same for every school */
- confirmation = getConfirmationString(examName);
- /* prepend all messages to description detail elements */
- confMessage.prepend(confirmation);
- rulesMessage.prepend(rules);
- resMessage.prepend(resources);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement