-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from AlexPeng517/dev
[Major Update] Refactor GradReviewer.tsx, integrate with firebase RTDB, refine review report html.
- Loading branch information
Showing
12 changed files
with
11,460 additions
and
5,930 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
// import { createRequire } from 'module' | ||
// const require = createRequire(import.meta.url); | ||
|
||
// const iconv = require('iconv-lite'); | ||
// let iconv; | ||
console.log("contentScript.js is running"); | ||
// (async () => { | ||
// // eslint-disable-next-line no-undef | ||
// const src = chrome.runtime.getURL('iconvImport.js'); | ||
// iconv = await import(src); | ||
// })(); | ||
|
||
// function loadScript(url) { | ||
// const script = document.createElement('script'); | ||
// script.src = chrome.runtime.getURL(url); | ||
// document.head.appendChild(script); | ||
// } | ||
// const loadScriptAsync = async (url) => { | ||
// await import(chrome.runtime.getURL("./firebase-app.js")); | ||
// await import(chrome.runtime.getURL("./firebase-database.js"));} | ||
// loadScriptAsync(); | ||
|
||
|
||
function parseHTMLTableElem(tableEl) { | ||
// console.log(tableEl); | ||
// const columns = Array.from(tableEl.querySelectorAll('th')).map(it => it.textContent) | ||
// console.log(columns); | ||
const rows = tableEl.querySelectorAll('tbody > tr') | ||
// console.log(rows); | ||
let courseList = []; | ||
for (let i = 2; i < rows.length-1; i++) { | ||
let course = { | ||
"courseID": "", | ||
"courseName": "", | ||
"courseType": "", | ||
"courseCredit": "", | ||
"courseGrade": "", | ||
}; | ||
const cells = Array.from(rows[i].querySelectorAll('td')) | ||
course.courseID = cells[0].innerText; | ||
course.courseName = cells[2].innerText; | ||
course.courseType = cells[3].innerText; | ||
course.courseCredit = parseInt(cells[5].innerText); | ||
if (cells[6].innerText ==="勞動服務通過"){ | ||
course.courseGrade = cells[6].innerText; | ||
}else{ | ||
course.courseGrade = parseInt(cells[6].innerText); | ||
} | ||
courseList.push(course); | ||
} | ||
console.log(courseList); | ||
return courseList; | ||
// console.log(courseList); | ||
// return JSON.stringify(Array.from(rows).map(row => { | ||
// const cells = Array.from(row.querySelectorAll('td')) | ||
// return columns.reduce((obj, col, idx) => { | ||
// obj[col] = cells[idx].textContent | ||
// return obj; | ||
// }, {}) | ||
// })); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
// eslint-disable-next-line no-undef | ||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
let gradeTablesContainer = document.getElementsByClassName("container"); | ||
let gradeTablesBySemester = gradeTablesContainer[1].getElementsByTagName("table"); | ||
let allCourses = { | ||
"courseList": [], | ||
}; | ||
console.log(gradeTablesContainer); | ||
console.log("printing gradeTablesBySemester"); | ||
console.log(gradeTablesBySemester); | ||
// console.log(parseHTMLTableElem(gradeTablesBySemester[0])); | ||
for (let i = 0; i < gradeTablesBySemester.length; i++) { | ||
allCourses.courseList = allCourses.courseList.concat(parseHTMLTableElem(gradeTablesBySemester[i])); | ||
} | ||
console.log(allCourses.courseList.length); | ||
console.log(JSON.stringify(allCourses)); | ||
|
||
|
||
|
||
if(request.action === "fetchGradeTable"){ | ||
|
||
sendResponse(JSON.stringify(allCourses)); | ||
} | ||
|
||
if(request.action === "fetchGeneralInfo"){ | ||
let generalInfoData = document.getElementsByClassName("container")[0].getElementsByClassName("shadow-none p-3 m-2 bg-light rounded")[0]; | ||
let generalInfoElements = generalInfoData.querySelectorAll("span"); | ||
let generalInfo = { | ||
"studentID": generalInfoElements[3].innerText, | ||
"studentName": generalInfoElements[0].innerText, | ||
}; | ||
console.log("generalInfo",generalInfo); | ||
sendResponse(JSON.stringify(generalInfo)); | ||
|
||
} | ||
}); | ||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import iconv from '../node_modules/iconv-lite' | ||
export function main(){ | ||
return iconv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.