-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: display unsubmitted assignments on the manaba home page #561
Draft
yudukikun5120
wants to merge
11
commits into
main
Choose a base branch
from
feat/asg-on-toppage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
25ba389
chore: TSC can detect missing impls for a feature
yudukikun5120 01e6a36
chore: enable `resolveJsonModule` in tsconfig
yudukikun5120 65ad6ce
chore: add trans for test and assignment
yudukikun5120 377d938
chore: the func renders unsubmitted asgs on home
yudukikun5120 ec2feb6
chore: add `featuresUnsubmittedAssignmentsOnHome`
yudukikun5120 5f43ad8
style: change the order of content scripts
yudukikun5120 7ccae17
Merge branch 'main' into feat/asg-on-toppage
yudukikun5120 66fd20e
Merge branch 'main' into feat/asg-on-toppage
yudukikun5120 f054455
refactor: rewrite `asgTable` in JSX
yudukikun5120 1c7cb4d
chore: enable `resolveJsonModule` to use JSON
yudukikun5120 be4a3e9
fix: remove the asg type for testing
yudukikun5120 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,19 @@ | ||
import { | ||
fetchAssignments, | ||
renderUnsubmittedAsgsOnHome, | ||
} from "../methods/unsubmittedAssignmentsOnHome" | ||
import { getStorage } from "../network/storage" | ||
|
||
getStorage({ | ||
kind: "sync", | ||
keys: "featuresUnsubmittedAssignmentsOnHome", | ||
callback: ({ featuresUnsubmittedAssignmentsOnHome }) => { | ||
if (featuresUnsubmittedAssignmentsOnHome) | ||
fetchAssignments().then( | ||
(assignments) => | ||
assignments && | ||
assignments.length && | ||
renderUnsubmittedAsgsOnHome(assignments, document) | ||
) | ||
}, | ||
}) |
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 @@ | ||
{ | ||
"homeLibraryQuery": "https://manaba.tsukuba.ac.jp/ct/home_library_query", | ||
"assignmentIcon": "/icon_collist_query.png" | ||
} |
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,130 @@ | ||
import dayjs from "dayjs" | ||
|
||
import { homeLibraryQuery, assignmentIcon } from "../json/uri.json" | ||
|
||
class Assignment { | ||
constructor( | ||
public id: string, | ||
public type: string, | ||
public title: string, | ||
public course: string, | ||
public deadline: Date | ||
) {} | ||
} | ||
|
||
const asgTableColumn = { | ||
type: 0, | ||
title: 1, | ||
course: 2, | ||
start: 3, | ||
end: 4, | ||
} as const | ||
|
||
const targetAsgType = new Set([ | ||
chrome.i18n.getMessage("test"), | ||
chrome.i18n.getMessage("assignment"), | ||
]) | ||
|
||
const parseRawDOM = async (url: string) => | ||
fetch(url) | ||
.then((res) => res.text()) | ||
.then((text) => new DOMParser().parseFromString(text, "text/html")) | ||
|
||
const asgPageTable = (asgPageDOM: Document) => | ||
asgPageDOM.querySelector<HTMLTableElement>(".contentbody-l table") | ||
|
||
const getAsgsFromTable = (table: HTMLTableElement) => | ||
Array.from(table.rows) | ||
.filter((row) => targetAsgType.has(getAsgType(row))) | ||
.filter((row) => getAsgDeadline(row)) | ||
.map( | ||
(row) => | ||
new Assignment( | ||
getAsgID(row), | ||
getAsgType(row), | ||
getAsgTitle(row), | ||
getAsgCourse(row), | ||
getAsgDeadline(row) | ||
) | ||
) | ||
|
||
/** | ||
* @example course_XXXXXXX_query_XXXXXXX, course_XXXXXXX_report_XXXXXXX | ||
*/ | ||
const getAsgID = (row: HTMLTableRowElement) => | ||
row.children[asgTableColumn.title] | ||
.querySelector<HTMLAnchorElement>("a") | ||
?.href.split("/") | ||
.pop() || "" | ||
|
||
const getAsgType = (row: HTMLTableRowElement) => | ||
row.children[asgTableColumn.type].textContent?.trim() || "" | ||
|
||
const getAsgTitle = (row: HTMLTableRowElement) => | ||
row.children[asgTableColumn.title].textContent?.trim() || "" | ||
|
||
const getAsgCourse = (row: HTMLTableRowElement) => | ||
row.children[asgTableColumn.course].textContent?.trim() || "" | ||
|
||
const getAsgDeadline = (row: HTMLTableRowElement) => | ||
new Date(row.children[asgTableColumn.end].textContent?.trim() || "") | ||
|
||
const fetchAssignments = () => | ||
parseRawDOM(homeLibraryQuery) | ||
.then((DOM) => asgPageTable(DOM)) | ||
.then((table) => table && getAsgsFromTable(table)) | ||
|
||
const renderUnsubmittedAsgsOnHome = ( | ||
assignments: Assignment[], | ||
document: Document | ||
) => { | ||
const container = document.querySelector( | ||
"#container > div.pagebody > div.my-course.my-courseV2 > div.contentbody-right > div.my-infolist.my-infolist-event.my-infolist-submitlog > div:nth-child(2)" | ||
) | ||
if (!container) return | ||
|
||
const asgTable = document.createElement("table") | ||
asgTable.classList.add("eventlist") | ||
const asgTableBody = document.createElement("tbody") | ||
asgTable.appendChild(asgTableBody) | ||
assignments.forEach((asg) => { | ||
const asgTableHeader = document.createElement("tr") | ||
asgTableHeader.classList.add("bordertop") | ||
const asgTableHeaderDate = document.createElement("td") | ||
asgTableHeaderDate.classList.add("center", "eventlist-day") | ||
asgTableHeaderDate.textContent = dayjs( | ||
asg.deadline.toLocaleDateString() | ||
).format("MM/DD") | ||
asgTableHeader.appendChild(asgTableHeaderDate) | ||
const asgTableHeaderTitle = document.createElement("td") | ||
asgTableHeaderTitle.classList.add("event-title") | ||
const asgTableHeaderTitleTime = document.createElement("span") | ||
asgTableHeaderTitleTime.classList.add("eventlist-day") | ||
asgTableHeaderTitleTime.textContent = dayjs(asg.deadline.toString()).format( | ||
"HH:mm" | ||
) | ||
asgTableHeaderTitle.appendChild(asgTableHeaderTitleTime) | ||
const asgTableHeaderTitleLink = document.createElement("a") | ||
asgTableHeaderTitleLink.href = | ||
"course_" + asg.id.split("_").slice(1).join("_") | ||
asgTableHeaderTitleLink.textContent = asg.title | ||
asgTableHeaderTitle.appendChild(asgTableHeaderTitleLink) | ||
const asgTableHeaderTitleIcon = document.createElement("img") | ||
asgTableHeaderTitleIcon.src = assignmentIcon | ||
asgTableHeaderTitleIcon.alt = "assignment icon" | ||
asgTableHeaderTitleIcon.classList.add("inline") | ||
asgTableHeaderTitleIcon.style.marginRight = "0.3em" | ||
asgTableHeaderTitleIcon.title = asg.type | ||
asgTableHeaderTitleLink.prepend(asgTableHeaderTitleIcon) | ||
const asgTableHeaderTitleCourse = document.createElement("a") | ||
asgTableHeaderTitleCourse.href = "course_" + asg.id.split("_")[1] | ||
asgTableHeaderTitleCourse.textContent = `[${asg.course}]` | ||
asgTableHeaderTitle.appendChild(asgTableHeaderTitleCourse) | ||
asgTableHeader.appendChild(asgTableHeaderTitle) | ||
asgTableBody.appendChild(asgTableHeader) | ||
}) | ||
const showmoreElement = container.querySelector("div.showmore") | ||
container.insertBefore(asgTable, showmoreElement) | ||
} | ||
|
||
export { fetchAssignments, renderUnsubmittedAsgsOnHome } |
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,16 @@ | ||
const Feature = [ | ||
"featuresAssignmentsColoring", | ||
"featuresAutoSaveReports", | ||
"featuresDeadlineHighlighting", | ||
"featuresRemoveConfirmation", | ||
"featuresFilterCourses", | ||
"featuresDragAndDrop", | ||
"featuresReportTemplate", | ||
"featuresRelativeGradesPosition", | ||
"featuresDisableForceFileSaving", | ||
"featuresUnsubmittedAssignmentsOnHome", | ||
] as const | ||
|
||
type Feature = typeof Feature[number] | ||
|
||
export { Feature } |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
renderUnsubmittedAsgsOnHome
has 46 lines of code (exceeds 25 allowed). Consider refactoring.