Tiny bugfix on semester name

This commit is contained in:
Lukas Zenick
2022-12-12 15:46:20 -06:00
committed by Lukas-Zenick
parent c12fca5a75
commit 4714386014

View File

@@ -170,33 +170,61 @@ function setDefaultOptions() {
}); });
} }
// scrape the registrar schedules page for caching the current active semesters async function getCurrentSemesters() {
function getCurrentSemesters() { let webData;
$.get("https://registrar.utexas.edu/schedules", function (response) { if(Object.keys(current_semesters).length > 0) {
if (response) { chrome.storage.local.set({
htmlToNode(response) semesterCache: current_semesters
.find(".callout2>ul>li>a") });
.each(function (i) { }
// only show as many semesters as we want to display async function goFetch(linkend="") {
if (i < Popup.num_semesters) { console.log("lk " + linkend)
let sem_name = $(this).text().trim(); return fetch("https://registrar.utexas.edu/schedules/" + linkend)
if (sem_name != "Course Schedule Archive") { .then((response) => {
// $("#semesters").append(`<option>${sem_name}</option>`); return response.text()
current_semesters[sem_name] = "code"; .then((data) => {
$.get($(this).attr("href"), function (response) { return data;
if (response) { }).catch((err) => {
let response_node = htmlToNode(response); console.log(err);
let name = response_node.find(".page-title").text().substring(17).trim(); })
response_node.find(".gobutton>a").each(function () { });
let link = $(this).attr("href"); }
var sem_num = link.substring(link.lastIndexOf("/") + 1).trim();
if (current_semesters[name] != sem_num) { await goFetch().then((data) => {webData = data});
current_semesters[name] = sem_num; if(webData == null) {
} webData = ""
}); }
} let arr = webData.split("\n");
}); let i = 0
} for(let row=0; row<arr.length; row++) {
let currentRow = arr[row]
if(currentRow.startsWith('<li><a href="https://registrar.utexas.edu/schedules/') && currentRow[52] != "a") {
let newWebData;
// let start = currentRow.indexOf('Schedule">')+10;
let start = Math.max(currentRow.lastIndexOf('Summer'), Math.max(currentRow.lastIndexOf('Spring'), currentRow.lastIndexOf('Fall')))
let end = currentRow.indexOf('</a></li>');
console.log(currentRow)
console.log(start + " " + end)
let name = currentRow.substring(start,end);
console.log("my name: " + name)
let num = currentRow.indexOf('"https://registrar.utexas.edu/schedules/">')+53;
let numend = currentRow.indexOf('" target');
let short_sem_num = currentRow.substring(num,numend);
current_semesters[name] = "code";
await goFetch(short_sem_num).then((data) => {newWebData = data});
arr2 = newWebData.split("\n")
for(let row2=0; row2<arr2.length; row2++) {
if(arr2[row2].startsWith('<div class="gobutton"><a href="')) {
let start2 = arr2[row2].indexOf('<div class="gobutton"><a href="')+31;
let end2 = arr2[row2].indexOf('" target="');
var scheduleLink = arr2[row2].substring(start2,end2);
var sem_num = scheduleLink.substring(scheduleLink.lastIndexOf("/") + 1).trim();
if (current_semesters[name] != sem_num) {
current_semesters[name] = sem_num;
} }
}); });
} }