Skip to content

Commit

Permalink
Merge pull request #61 from kyoto-u/fix/name
Browse files Browse the repository at this point in the history
Fixed variable name
  • Loading branch information
das08 authored Dec 22, 2021
2 parents dfc8ac1 + 9e63760 commit badccbc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions src/content_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export let CPsettings: Settings;

export async function loadAndMergeAssignmentList(courseSiteInfos: Array<CourseSiteInfo>, useAssignmentCache: boolean, useQuizCache: boolean): Promise<Array<Assignment>> {
// ストレージから前回保存したassignmentListを読み込む
const oldAssignmentList = convertArrayToAssignment(await loadFromLocalStorage("TSkadaiList"));
const oldQuizList = convertArrayToAssignment(await loadFromLocalStorage("TSQuizList"));
const oldAssignmentList = convertArrayToAssignment(await loadFromLocalStorage("CS_AssignmentList"));
const oldQuizList = convertArrayToAssignment(await loadFromLocalStorage("CS_QuizList"));
let newAssignmentList = [];
let newQuizList = [];

Expand All @@ -49,7 +49,7 @@ export async function loadAndMergeAssignmentList(courseSiteInfos: Array<CourseSi
if (k.status === "fulfilled") newAssignmentList.push(k.value);
}
// 取得した時間を保存
await saveToLocalStorage("TSkadaiFetchedTime", nowTime);
await saveToLocalStorage("CS_AssignmentFetchTime", nowTime);
assignmentFetchedTime = nowTime;
}
// 保存してあったものとマージする
Expand All @@ -73,19 +73,19 @@ export async function loadAndMergeAssignmentList(courseSiteInfos: Array<CourseSi
if (k.status === "fulfilled") newQuizList.push(k.value);
}
// 取得した時間を保存
await saveToLocalStorage("TSquizFetchedTime", nowTime);
await saveToLocalStorage("CS_QuizFetchTime", nowTime);
quizFetchedTime = nowTime;
}
const mergedQuizList = compareAndMergeAssignmentList(oldQuizList, newQuizList);

// マージ後のkadaiListをストレージに保存する
await saveToLocalStorage("TSkadaiList", mergedAssignmentListNoMemo);
await saveToLocalStorage("TSQuizList", mergedQuizList);
await saveToLocalStorage("CS_AssignmentList", mergedAssignmentListNoMemo);
await saveToLocalStorage("CS_QuizList", mergedQuizList);

mergedAssignmentList = mergeIntoAssignmentList(mergedAssignmentList, mergedQuizList);

// メモ一覧を読み込む
const memoList = convertArrayToAssignment(await loadFromLocalStorage("TSkadaiMemoList"));
const memoList = convertArrayToAssignment(await loadFromLocalStorage("CS_MemoList"));
// さらにメモもマージする
mergedAssignmentList = mergeIntoAssignmentList(mergedAssignmentList, memoList);
mergedAssignmentList = sortAssignmentList(mergedAssignmentList);
Expand All @@ -97,14 +97,14 @@ async function loadConfigs() {
CPsettings = await loadSettings();
assignmentCacheInterval = CPsettings.getAssignmentCacheInterval;
quizCacheInterval = CPsettings.getQuizCacheInterval;
CPsettings.displayCheckedKadai = CPsettings.getDisplayCheckedKadai;
assignmentFetchedTime = await loadFromLocalStorage("TSkadaiFetchedTime", "undefined");
quizFetchedTime = await loadFromLocalStorage("TSquizFetchedTime", "undefined");
CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment;
assignmentFetchedTime = await loadFromLocalStorage("CS_AssignmentFetchTime", "undefined");
quizFetchedTime = await loadFromLocalStorage("CS_QuizFetchTime", "undefined");
}

async function loadCourseIDList() {
courseIDList = getCourseIDList();
await saveToLocalStorage("TSlectureids", courseIDList);
await saveToLocalStorage("CS_CourseInfo", courseIDList);
}

async function main() {
Expand Down
28 changes: 14 additions & 14 deletions src/eventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ async function toggleFinishedFlag(event: any): Promise<void> {
const assignmentID = event.target.id;
let assignmentList: Array<Assignment>;
// "m"から始まるものはメモ,"q"から始まるものはクイズを表してる
if (assignmentID[0] === "m") assignmentList = convertArrayToAssignment(await loadFromLocalStorage("TSkadaiMemoList"));
else if (assignmentID[0] === "q") assignmentList = convertArrayToAssignment(await loadFromLocalStorage("TSQuizList"));
else assignmentList = convertArrayToAssignment(await loadFromLocalStorage("TSkadaiList"));
if (assignmentID[0] === "m") assignmentList = convertArrayToAssignment(await loadFromLocalStorage("CS_MemoList"));
else if (assignmentID[0] === "q") assignmentList = convertArrayToAssignment(await loadFromLocalStorage("CS_QuizList"));
else assignmentList = convertArrayToAssignment(await loadFromLocalStorage("CS_AssignmentList"));

const updatedAssignmentList = [];
for (const assignment of assignmentList) {
Expand Down Expand Up @@ -110,9 +110,9 @@ async function toggleFinishedFlag(event: any): Promise<void> {
updatedAssignmentList.push(new Assignment(assignment.courseSiteInfo, updatedAssignmentEntries, assignment.isRead));
}

if (assignmentID[0] === "m") await saveToLocalStorage("TSkadaiMemoList", updatedAssignmentList);
else if (assignmentID[0] === "q") await saveToLocalStorage("TSQuizList", updatedAssignmentList);
else await saveToLocalStorage("TSkadaiList", updatedAssignmentList);
if (assignmentID[0] === "m") await saveToLocalStorage("CS_MemoList", updatedAssignmentList);
else if (assignmentID[0] === "q") await saveToLocalStorage("CS_QuizList", updatedAssignmentList);
else await saveToLocalStorage("CS_AssignmentList", updatedAssignmentList);

// NavBarを再描画
await reloadNavBar(courseIDList, true);
Expand All @@ -134,7 +134,7 @@ async function updateSettings(event: any, type: string): Promise<void> {
}

const settings = new Settings();
const oldSettings = await loadFromLocalStorage("TSSettings");
const oldSettings = await loadFromLocalStorage("CS_Settings");
for (const i in DefaultSettings) {
// @ts-ignore
settings[i] = oldSettings[i] ?? DefaultSettings[i];
Expand Down Expand Up @@ -163,7 +163,7 @@ async function updateSettings(event: any, type: string): Promise<void> {
CPsettings[settingsID] = settingsValue;
}

saveToLocalStorage("TSSettings", settings);
saveToLocalStorage("CS_Settings", settings);

// NavBarを再描画
await reloadNavBar(courseIDList, true);
Expand All @@ -176,7 +176,7 @@ async function addMemo(): Promise<void> {
// @ts-ignore
const memoDueDateTimestamp = new Date(document.querySelector(".todoDue").value).getTime() / 1000;

let memoList = await loadFromLocalStorage("TSkadaiMemoList");
let memoList = await loadFromLocalStorage("CS_MemoList");
const memoEntry = new AssignmentEntry(genUniqueStr(), memoTitle, memoDueDateTimestamp, memoDueDateTimestamp, true, false, false, "");
const memo = new Assignment(new CourseSiteInfo(courseID, courseID), [memoEntry], true);

Expand All @@ -193,7 +193,7 @@ async function addMemo(): Promise<void> {
} else {
memoList = [memo];
}
saveToLocalStorage("TSkadaiMemoList", memoList);
saveToLocalStorage("CS_MemoList", memoList);

// Redraw miniSakai menu
while (miniSakai.firstChild) {
Expand All @@ -205,7 +205,7 @@ async function addMemo(): Promise<void> {
miniSakai.remove();
assignmentDiv.remove();
const assignmentList = mergeIntoAssignmentList(mergedAssignmentListNoMemo, memoList);
const quizList = await loadFromLocalStorage("TSQuizList");
const quizList = await loadFromLocalStorage("CS_QuizList");
await displayMiniSakai(mergeIntoAssignmentList(assignmentList, quizList), courseIDList);

// NavBarを再描画
Expand All @@ -214,7 +214,7 @@ async function addMemo(): Promise<void> {

async function deleteMemo(event: any): Promise<void> {
const memoID = event.target.id;
const memoList = convertArrayToAssignment(await loadFromLocalStorage("TSkadaiMemoList"));
const memoList = convertArrayToAssignment(await loadFromLocalStorage("CS_MemoList"));
const deletedMemoList = [];
for (const memo of memoList) {
const memoEntries = [];
Expand All @@ -234,9 +234,9 @@ async function deleteMemo(event: any): Promise<void> {
miniSakai.remove();
assignmentDiv.remove();

saveToLocalStorage("TSkadaiMemoList", deletedMemoList);
saveToLocalStorage("CS_MemoList", deletedMemoList);
const assignmentList = mergeIntoAssignmentList(mergedAssignmentListNoMemo, deletedMemoList);
const quizList = await loadFromLocalStorage("TSQuizList");
const quizList = await loadFromLocalStorage("CS_QuizList");
await displayMiniSakai(mergeIntoAssignmentList(assignmentList, quizList), courseIDList);

// NavBarを再描画
Expand Down
4 changes: 2 additions & 2 deletions src/minisakai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function createMiniSakai(assignmentList: Array<Assignment>, courseSiteInfos: Arr
}

async function createSettingsTab(root: Element): Promise<void> {
createSettingItem(root, chrome.i18n.getMessage('settings_color_checked_item'), CPsettings.getDisplayCheckedKadai, "displayCheckedKadai");
createSettingItem(root, chrome.i18n.getMessage('settings_color_checked_item'), CPsettings.getDisplayCheckedAssignment, "displayCheckedAssignment");
createSettingItem(root, chrome.i18n.getMessage('settings_display_late_submit_assignment'), CPsettings.getDisplayLateSubmitAssignment, "displayLateSubmitAssignment");
createSettingItem(root, chrome.i18n.getMessage('settings_assignment_cache'), CPsettings.getAssignmentCacheInterval, "assignmentCacheInterval");
createSettingItem(root, chrome.i18n.getMessage('settings_quizzes_cache'), CPsettings.getQuizCacheInterval, "quizCacheInterval");
Expand Down Expand Up @@ -295,7 +295,7 @@ function createNavBarNotification(courseSiteInfos: Array<CourseSiteInfo>, assign
return assignment.courseSiteInfo.courseID === courseID;
});
if (q !== -1) {
const closestTime = (CPsettings.displayCheckedKadai) ? assignmentList[q].closestDueDateTimestamp : assignmentList[q].closestDueDateTimestampExcludeFinished;
const closestTime = (CPsettings.displayCheckedAssignment) ? assignmentList[q].closestDueDateTimestamp : assignmentList[q].closestDueDateTimestampExcludeFinished;
if (!assignmentList[q].isRead && closestTime !== -1) {
defaultTab[j].classList.add("cs-notification-badge");
}
Expand Down
12 changes: 6 additions & 6 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { convertArrayToSettings } from "./utils";
export class Settings {
assignmentCacheInterval?: number;
quizCacheInterval?: number;
displayCheckedKadai?: boolean;
displayCheckedAssignment?: boolean;
displayLateSubmitAssignment?: boolean;
topColorDanger?: string;
topColorWarning?: string;
Expand All @@ -22,8 +22,8 @@ export class Settings {
get getQuizCacheInterval(): number {
return this.quizCacheInterval ? this.quizCacheInterval : DefaultSettings.quizCacheInterval;
}
get getDisplayCheckedKadai(): boolean {
return this.displayCheckedKadai !== undefined ? this.displayCheckedKadai : DefaultSettings.displayCheckedKadai;
get getDisplayCheckedAssignment(): boolean {
return this.displayCheckedAssignment !== undefined ? this.displayCheckedAssignment : DefaultSettings.displayCheckedAssignment;
}
get getDisplayLateSubmitAssignment(): boolean {
return this.displayLateSubmitAssignment !== undefined ? this.displayLateSubmitAssignment : DefaultSettings.displayLateSubmitAssignment;
Expand Down Expand Up @@ -51,7 +51,7 @@ export class Settings {
export class DefaultSettings extends Settings {
static assignmentCacheInterval = 120;
static quizCacheInterval = 600;
static displayCheckedKadai = true;
static displayCheckedAssignment = true;
static displayLateSubmitAssignment = false;
static topColorDanger = "#f78989";
static topColorWarning = "#fdd783";
Expand All @@ -62,9 +62,9 @@ export class DefaultSettings extends Settings {
}

export async function loadSettings(): Promise<Settings>{
const settingsArr = await loadFromLocalStorage("TSSettings");
const settingsArr = await loadFromLocalStorage("CS_Settings");
const CPsettings = convertArrayToSettings(settingsArr);
CPsettings.displayCheckedKadai = CPsettings.getDisplayCheckedKadai;
CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment;
return CPsettings;
}

Expand Down
8 changes: 4 additions & 4 deletions src/subsakai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ async function updateSubSakai(root: Element) {
const hostname = (await getKeys())[0];
let mergedAssignmentList: Array<Assignment>;

const assignmentList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "TSkadaiList"));
const quizList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "TSQuizList"));
const assignmentMemoList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "TSkadaiMemoList"));
const courseIDs = (await loadFromLocalStorage2(hostname, "TSlectureids")) as Array<CourseSiteInfo>;
const assignmentList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "CS_AssignmentList"));
const quizList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "CS_QuizList"));
const assignmentMemoList = convertArrayToAssignment(await loadFromLocalStorage2(hostname, "CS_MemoList"));
const courseIDs = (await loadFromLocalStorage2(hostname, "CS_CourseInfo")) as Array<CourseSiteInfo>;
mergedAssignmentList = mergeIntoAssignmentList(assignmentList, quizList);
mergedAssignmentList = mergeIntoAssignmentList(mergedAssignmentList, assignmentMemoList);
mergedAssignmentList = sortAssignmentList(mergedAssignmentList);
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function updateIsReadFlag(assignmentList: Array<Assignment>): void {
updatedAssignmentList.push(assignment);
}
}
saveToLocalStorage("TSkadaiList", updatedAssignmentList);
saveToLocalStorage("CS_AssignmentList", updatedAssignmentList);
}
}

Expand All @@ -100,7 +100,7 @@ function convertArrayToSettings(arr: any): Settings {
const settings = new Settings();
settings.assignmentCacheInterval = arr.assignmentCacheInterval;
settings.quizCacheInterval = arr.quizCacheInterval;
settings.displayCheckedKadai = arr.displayCheckedKadai;
settings.displayCheckedAssignment = arr.displayCheckedAssignment;
settings.displayLateSubmitAssignment = arr.displayLateSubmitAssignment;
settings.topColorDanger = arr.topColorDanger;
settings.topColorWarning = arr.topColorWarning;
Expand Down

0 comments on commit badccbc

Please sign in to comment.