Skip to content

Commit

Permalink
add: アンケート、小テストを取得
Browse files Browse the repository at this point in the history
  • Loading branch information
SIY1121 committed Sep 30, 2020
1 parent bd6b7b0 commit 8d31bab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
src/config/config.json
src/config/config.json
dist.zip
22 changes: 15 additions & 7 deletions src/content-scripts/manabaMain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ManabaTodo, ManabaTodoStatus } from '../types/manabaTodo'
import { ManabaTodo, ManabaTodoStatus, TodoType } from '../types/manabaTodo'
import { Message } from '../types/message'

/**
Expand Down Expand Up @@ -38,12 +38,12 @@ async function listCource(): Promise<{ link: string; title: string }[]> {
}

/**
* 指定されたコースのレポートを取得
* 指定されたコースのレポート、アンケート、小テストを取得
* @param link {string} コースへのリンク
* @returns {{title: string, link: string, deadline: string, status: string}[]} link
*/
async function getReports(link: string): Promise<ManabaTodo[]> {
const raw = await (await fetch(`${link}_report`)).text()
async function getReports(link: string, type: TodoType): Promise<ManabaTodo[]> {
const raw = await (await fetch(`${link}_${type}`)).text()
const dom = createElementFromHTML(raw)

const courceName = dom.querySelector('#coursename')?.textContent || ''
Expand All @@ -69,7 +69,7 @@ async function getReports(link: string): Promise<ManabaTodo[]> {
status = 'todo'

return {
type: 'report',
type: type,
courceName,
lectureCode,
title: tds[0].querySelector('a')?.textContent || '',
Expand All @@ -81,12 +81,20 @@ async function getReports(link: string): Promise<ManabaTodo[]> {
}

/**
* 全てのコースのすべてのレポートを取得
* 全てのコースのすべてのレポート、アンケート、小テストを取得
*/
async function getAllReports(): Promise<ManabaTodo[]> {
const list = await listCource()
return (
await Promise.all(list.map(async (c) => await getReports(c.link)))
await Promise.all(
list.map(async (c) =>
[
await getReports(c.link, 'report'),
await getReports(c.link, 'query'),
await getReports(c.link, 'survey'),
].flat()
)
)
).flat()
}

Expand Down
4 changes: 3 additions & 1 deletion src/types/manabaTodo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ManabaTodo {
type: 'report' | 'survey'
type: TodoType
courceName: string
lectureCode: string
title: string
Expand All @@ -9,3 +9,5 @@ export interface ManabaTodo {
}

export type ManabaTodoStatus = 'todo' | 'done' | 'overdue'

export type TodoType = 'report' | 'survey' | 'query'

0 comments on commit 8d31bab

Please sign in to comment.