var courses; // get the courses from storage chrome.storage.sync.get('savedCourses', function(data) { //find, build, and show the messages for the conflicts in the saved courses chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) { var isConflicted = []; if(response.isConflict){ var between = response.between; var text = ""; for(var i = 0; i"+text+""); } }); courses = data.savedCourses; if(courses.length != 0){ $("#empty").hide(); } // build and append the course list element for(var i = 0; i

"+department + " "+course_nbr+""+" with "+profname+" ("+courses[i].unique+")"+"

"; $("#courseList").append(listhtml); } }); /* prettify the name for the conflict messages*/ function getSimpleName(coursename, unique){ var department = coursename.substring(0,coursename.search(/\d/)-2); var course_nbr = coursename.substring(coursename.search(/\d/),coursename.indexOf(" ",coursename.search(/\d/))); return department+" "+course_nbr+" ("+unique+")"; } /* Update the conflict messages */ function updateConflicts(){ chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) { var isConflicted = []; if(response.isConflict){ var between = response.between; var text = ""; for(var i = 0; i"+text+""); } }); } /* Handle the button clicks */ $(document).ready(function() { $("#courseList li").click(function(){ $(this).find("#listMoreInfo").click(function(){ window.open(courses[$(this).closest("li").attr("id")].link); }); /* clear the conflict messages, then remove the course and updateConflicts. update the tabs*/ $(this).find("#listRemove").click(function(){ $(thisForm).closest("ul").find("> p").remove(); var thisForm = this; chrome.runtime.sendMessage({command: "courseStorage",course: courses[$(thisForm).closest("li").attr("id")], action:"remove"}, function(response) { $(thisForm).closest("li").fadeOut(200); if($(thisForm).closest("ul").children(':visible').length===1){ $("#courseList").fadeOut(300,function(){ $("#empty").fadeIn(200); }); } updateConflicts(); chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {command: "update"}); }); }); }); /* Show the times popout and more info options*/ if($(this).find("#moreInfo").is(":hidden")){ $(this).find("#moreInfo").fadeIn(200); } else{ $(this).find("#moreInfo").fadeOut(200); } }); $("#clear").click(function(){ clear(); }); $("#schedule").click(function(){ chrome.tabs.create({ 'url': 'https://registrar.utexas.edu/schedules'}); }); $("#open").click(function(){ chrome.tabs.create({ 'url': 'chrome://extensions/?options=' + chrome.runtime.id }); }); }); /* convert from the dtarr and maek the time lines*/ function makeLine(index){ var datetimearr = courses[index].datetimearr; //converted times back var dtmap = new Map([]); for(var i = 0; i: "+timearr[i].split(",")[0]+" to "+timearr[i].split(",")[1]+"
"; } return output; } /*Clear the list and the storage of courses*/ function clear(){ chrome.storage.sync.set({savedCourses: []}); chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {command: "update"}); }); console.log("cleared"); $("#courseList").fadeOut(300,function(){ $("#empty").fadeIn(200); }); }