From 25f1d79a712c803b04288b6675067cc7ca379bae Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 13:14:18 +0900 Subject: [PATCH 01/10] renamed `relaxPandA` to `noAssignment` --- manifest.json | 2 +- public/img/{relaxPanda.png => noAssignment.png} | Bin public/views/minisakai.mustache | 6 +++--- src/minisakai.ts | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) rename public/img/{relaxPanda.png => noAssignment.png} (100%) diff --git a/manifest.json b/manifest.json index ba3e257..3f0de5f 100644 --- a/manifest.json +++ b/manifest.json @@ -36,7 +36,7 @@ "web_accessible_resources": [ "css/comfortable-sakai.css", "img/logo.png", - "img/relaxPanda.png", + "img/noAssignment.png", "img/miniSakaiBtn.png", "views/minisakai.mustache" ] diff --git a/public/img/relaxPanda.png b/public/img/noAssignment.png similarity index 100% rename from public/img/relaxPanda.png rename to public/img/noAssignment.png diff --git a/public/views/minisakai.mustache b/public/views/minisakai.mustache index 6315391..2206210 100644 --- a/public/views/minisakai.mustache +++ b/public/views/minisakai.mustache @@ -213,12 +213,12 @@ {{/display.lateSubmit}} - {{#showRelaxPandA}} + {{#noAssignment}}
-

{{titles.relaxPandA}}

+

{{titles.noAssignment}}

logo
- {{/showRelaxPandA}} + {{/noAssignment}} {{^subset}} diff --git a/src/minisakai.ts b/src/minisakai.ts index 2fa94c3..f336c78 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -114,7 +114,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< return elements; }; - let relaxPandA = null; + let noAssignmentImg = null; let assignmentCnt = 0; if (assignmentList.length !== 0) { for (const assignment of assignmentList) { @@ -122,8 +122,8 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< } } if (assignmentList.length === 0 || assignmentCnt === 0) { - relaxPandA = { - img: chrome.extension.getURL("img/relaxPanda.png"), + noAssignmentImg = { + img: chrome.extension.getURL("img/noAssignment.png"), }; } @@ -135,7 +135,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< miniSakaiLogo: chrome.extension.getURL("img/logo.png"), VERSION: VERSION, subset: subset, - showRelaxPandA: relaxPandA, + noAssignment: noAssignmentImg, elements: { danger: sortElements(dangerElements), warning: sortElements(warningElements), @@ -160,7 +160,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< due14d: chrome.i18n.getMessage("due14d"), dueOver14d: chrome.i18n.getMessage("dueOver14d"), duePassed: chrome.i18n.getMessage("duePassed"), - relaxPandA: chrome.i18n.getMessage("no_available_assignments"), + noAssignment: chrome.i18n.getMessage("no_available_assignments"), }, todoBox: { courseName: chrome.i18n.getMessage("todo_box_course_name"), From 125ba1b817731297599554994bf8e6d58588f87b Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 13:20:23 +0900 Subject: [PATCH 02/10] fixed a bit --- src/minisakai.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/minisakai.ts b/src/minisakai.ts index f336c78..ceab633 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -127,6 +127,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< }; } + // Create dict of data for miniSakai const templateVars = { fetchedTime: { assignment: assignmentFetchedTimeString, @@ -387,19 +388,20 @@ function overrideCSSColor() { elem.setAttribute("style", "background:" + color + "!important"); } }; - overwriteborder("cs-assignment-danger", CPsettings.getMiniColorDanger); - overwriteborder("cs-assignment-success", CPsettings.getMiniColorSuccess); - overwriteborder("cs-assignment-warning", CPsettings.getMiniColorWarning); + + // Overwrite colors overwritebackground("cs-course-danger", CPsettings.getMiniColorDanger); - overwritebackground("cs-course-success", CPsettings.getMiniColorSuccess); overwritebackground("cs-course-warning", CPsettings.getMiniColorWarning); - + overwritebackground("cs-course-success", CPsettings.getMiniColorSuccess); overwritebackground("cs-tab-danger", CPsettings.getTopColorDanger); - overwritebackground("cs-tab-success", CPsettings.getTopColorSuccess); overwritebackground("cs-tab-warning", CPsettings.getTopColorWarning); + overwritebackground("cs-tab-success", CPsettings.getTopColorSuccess); + overwriteborder("cs-assignment-danger", CPsettings.getMiniColorDanger); + overwriteborder("cs-assignment-warning", CPsettings.getMiniColorWarning); + overwriteborder("cs-assignment-success", CPsettings.getMiniColorSuccess); overwriteborder("cs-tab-danger", CPsettings.getTopColorDanger); - overwriteborder("cs-tab-success", CPsettings.getTopColorSuccess); overwriteborder("cs-tab-warning", CPsettings.getTopColorWarning); + overwriteborder("cs-tab-success", CPsettings.getTopColorSuccess); } export { From 327d87e7f71cd2eee59bd4054a871e9dd86d6a95 Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 13:27:50 +0900 Subject: [PATCH 03/10] renamed element --- src/minisakai.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/minisakai.ts b/src/minisakai.ts index ceab633..cbd2c2f 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -203,7 +203,7 @@ function createMiniSakai(assignmentList: Array, courseSiteInfos: Arr /** * Initialize Settings tab. */ -async function createSettingsTab(root: Element): Promise { +async function createSettingsTab(root: Element) { 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"); @@ -371,9 +371,9 @@ function deleteFavoritesBarNotification(): void { */ function overrideCSSColor() { const overwriteborder = function (className: string, color: string | undefined) { - const dangerelem = document.getElementsByClassName(className); - for (let i = 0; i < dangerelem.length; i++) { - const elem = dangerelem[i] as HTMLElement; + const element = document.getElementsByClassName(className); + for (let i = 0; i < element.length; i++) { + const elem = element[i] as HTMLElement; const attr = "solid 2px " + color; (elem.style)["border-top"] = attr; (elem.style)["border-left"] = attr; @@ -382,9 +382,9 @@ function overrideCSSColor() { } }; const overwritebackground = function (className: string, color: string | undefined) { - const dangerelem = document.getElementsByClassName(className); - for (let i = 0; i < dangerelem.length; i++) { - const elem = dangerelem[i] as HTMLElement; + const element = document.getElementsByClassName(className); + for (let i = 0; i < element.length; i++) { + const elem = element[i] as HTMLElement; elem.setAttribute("style", "background:" + color + "!important"); } }; From 476ac5c26c1c0e677ee080f810196a9bda586c86 Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:39:25 +0900 Subject: [PATCH 04/10] fixed a bug --- public/views/minisakai.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/minisakai.mustache b/public/views/minisakai.mustache index 2206210..cd78b91 100644 --- a/public/views/minisakai.mustache +++ b/public/views/minisakai.mustache @@ -14,7 +14,7 @@

{{titles.quizFetchedTime}}

-

{{fetchedTime.assignment}}

+

{{fetchedTime.quiz}}

{{/subset}} From e3d9a3b53c7a876f75dabb2bf9ab295002d30459 Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:44:02 +0900 Subject: [PATCH 05/10] load config from settings.ts --- src/content_script.ts | 61 +++++++++++++++++++++++-------------------- src/settings.ts | 42 +++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/content_script.ts b/src/content_script.ts index b625ae4..415837e 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -14,26 +14,28 @@ import { updateIsReadFlag, useCache, } from "./utils"; -import { Settings, loadSettings } from "./settings"; +import { Config, loadConfigs } from "./settings"; + +// export const baseURL = getBaseURL(); +// export const VERSION = chrome.runtime.getManifest().version; +// export let assignmentFetchedTime: number | undefined; +// export let quizFetchedTime: number | undefined; +// export let assignmentCacheInterval: number; +// export let quizCacheInterval: number; +// export let CPsettings: Settings; -export const baseURL = getBaseURL(); -export const VERSION = chrome.runtime.getManifest().version; -export let assignmentCacheInterval: number; -export let quizCacheInterval: number; -export let assignmentFetchedTime: number | undefined; -export let quizFetchedTime: number | undefined; export let courseIDList: Array; export let mergedAssignmentList: Array; export let mergedAssignmentListNoMemo: Array; -export let CPsettings: Settings; /** * Load old assignments/quizzes from storage and fetch new assignments/quizzes from Sakai. + * @param {Config} config * @param {CourseSiteInfo[]} courseSiteInfos * @param {boolean} useAssignmentCache * @param {boolean} useQuizCache */ -export async function loadAndMergeAssignmentList(courseSiteInfos: Array, useAssignmentCache: boolean, useQuizCache: boolean): Promise> { +export async function loadAndMergeAssignmentList(config: Config ,courseSiteInfos: Array, useAssignmentCache: boolean, useQuizCache: boolean): Promise> { // Load old assignments and quizzes from local storage const oldAssignmentList = convertArrayToAssignment(await loadFromLocalStorage("CS_AssignmentList")); const oldQuizList = convertArrayToAssignment(await loadFromLocalStorage("CS_QuizList")); @@ -48,7 +50,7 @@ export async function loadAndMergeAssignmentList(courseSiteInfos: Array { CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment; return CPsettings; } + +export interface Config { + baseURL: string; + version: string; + CPSettings: Settings; + fetchedTime: { + assignment: number; + quiz: number; + }; + cacheInterval: { + assignment: number; + quiz: number; + }; +} + +/** + * Load configurations from local storage + */ +export async function loadConfigs(): Promise { + const baseURL = getBaseURL(); + const VERSION = chrome.runtime.getManifest().version; + const CPsettings = await loadSettings(); + CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment; + const assignmentCacheInterval = CPsettings.getAssignmentCacheInterval; + const quizCacheInterval = CPsettings.getQuizCacheInterval; + const assignmentFetchedTime = await loadFromLocalStorage("CS_AssignmentFetchTime", "undefined"); + const quizFetchedTime = await loadFromLocalStorage("CS_QuizFetchTime", "undefined"); + return { + baseURL: baseURL, + version: VERSION, + CPSettings: CPsettings, + cacheInterval: { + assignment: assignmentCacheInterval, + quiz: quizCacheInterval, + }, + fetchedTime: { + assignment: assignmentFetchedTime, + quiz: quizFetchedTime, + }, + }; +} From 962bdd9230581a89e44840ead526cb2eea9318ae Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:45:13 +0900 Subject: [PATCH 06/10] inserted await for function that uses config --- src/eventListener.ts | 25 ++++++++------ src/minisakai.ts | 77 ++++++++++++++++++++++++-------------------- src/subsakai.ts | 2 +- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/eventListener.ts b/src/eventListener.ts index b20d39e..f9f13d9 100644 --- a/src/eventListener.ts +++ b/src/eventListener.ts @@ -2,8 +2,8 @@ import { assignmentDiv, miniSakai } from "./dom"; import { loadFromLocalStorage, saveToLocalStorage } from "./storage"; import { CourseSiteInfo, Assignment, AssignmentEntry } from "./model"; import { convertArrayToAssignment, genUniqueID, mergeIntoAssignmentList } from "./utils"; -import { CPsettings, courseIDList, loadAndMergeAssignmentList, mergedAssignmentListNoMemo } from "./content_script"; -import { DefaultSettings } from "./settings"; +import { courseIDList, loadAndMergeAssignmentList, mergedAssignmentListNoMemo } from "./content_script"; +import { DefaultSettings, loadConfigs } from "./settings"; import { createFavoritesBarNotification, deleteFavoritesBarNotification, displayMiniSakai } from "./minisakai"; let toggle = false; @@ -125,15 +125,18 @@ async function toggleFinishedFlag(event: any): Promise { */ async function updateSettings(event: any, type: string): Promise { const settingsID = event.target.id; - let settingsValue = event.currentTarget.value; + let settingsValue = event.target.value; + // console.log("Settings...", settingsID, settingsValue,event.target.value) + const config = await loadConfigs(); + const CPSettings = config.CPSettings; // Type of Settings switch (type) { case "check": - settingsValue = event.currentTarget.checked; + settingsValue = event.target.checked; break; case "number": - settingsValue = parseInt(event.currentTarget.value); + settingsValue = parseInt(event.target.value); break; case "string": break; @@ -146,7 +149,7 @@ async function updateSettings(event: any, type: string): Promise { ]; for (const k of colorList) { // @ts-ignore - CPsettings[k] = DefaultSettings[k]; + CPSettings[k] = DefaultSettings[k]; const q = document.getElementById(k); if (q) { // @ts-ignore @@ -155,10 +158,11 @@ async function updateSettings(event: any, type: string): Promise { } } else { // @ts-ignore - CPsettings[settingsID] = settingsValue; + CPSettings[settingsID] = settingsValue; } - saveToLocalStorage("CS_Settings", CPsettings); + saveToLocalStorage("CS_Settings", CPSettings); + console.log("CPSettings", CPSettings); await redrawFavoritesBar(courseIDList, true); } @@ -253,8 +257,9 @@ async function editFavoritesMessage(): Promise { */ async function redrawFavoritesBar(courseIDList: Array, useCache: boolean): Promise { deleteFavoritesBarNotification(); - const newAssignmentList = await loadAndMergeAssignmentList(courseIDList, useCache, useCache); - createFavoritesBarNotification(courseIDList, newAssignmentList); + const config = await loadConfigs(); + const newAssignmentList = await loadAndMergeAssignmentList(config, courseIDList, useCache, useCache); + await createFavoritesBarNotification(courseIDList, newAssignmentList); } /** diff --git a/src/minisakai.ts b/src/minisakai.ts index cbd2c2f..d4e1e0d 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -1,7 +1,7 @@ import { Assignment, CourseSiteInfo, DisplayAssignment, DisplayAssignmentEntry } from "./model"; import { createCourseIDMap, getDaysUntil, formatTimestamp, nowTime } from "./utils"; import { appendChildAll, cloneElem, hamburger, miniSakai, SettingsDom } from "./dom"; -import { CPsettings, assignmentFetchedTime, quizFetchedTime, VERSION } from "./content_script"; +// import { CPsettings, assignmentFetchedTime, quizFetchedTime, VERSION } from "./content_script"; import { addMemo, deleteMemo, @@ -14,6 +14,7 @@ import { } from "./eventListener"; // @ts-ignore import Mustache = require("mustache"); +import { loadConfigs } from "./settings"; /** * Create a button to open miniSakai @@ -30,9 +31,12 @@ function createMiniSakaiBtn(): void { /** * Using template engine to generate miniSakai list. */ -export function createMiniSakaiGeneralized(root: Element, assignmentList: Array, courseSiteInfos: Array, subset: boolean, insertionProcess: (rendered: string) => void): void { - const assignmentFetchedTimeString = formatTimestamp(assignmentFetchedTime); - const quizFetchedTimeString = formatTimestamp(quizFetchedTime); +export async function createMiniSakaiGeneralized(root: Element, assignmentList: Array, courseSiteInfos: Array, subset: boolean, insertionProcess: (rendered: string) => void): Promise { + const config = await loadConfigs(); + console.log("minisakai config", config) + const assignmentFetchedTimeString = formatTimestamp(config.fetchedTime.assignment); + const quizFetchedTimeString = formatTimestamp(config.fetchedTime.quiz); + console.log("timestamps", assignmentFetchedTimeString, quizFetchedTimeString) const courseSiteList: Array = []; @@ -90,7 +94,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< appendElement(courseName, otherElements); break; case "duePassed": - const showLateSubmitAssignment = CPsettings ? CPsettings.getDisplayLateSubmitAssignment : false; + const showLateSubmitAssignment = config.CPSettings ? config.CPSettings.getDisplayLateSubmitAssignment : false; if (showLateSubmitAssignment && getDaysUntil(nowTime, assignmentEntry.getCloseDateTimestamp * 1000) !== "duePassed") { appendElement(courseName, lateSubmitElements); } @@ -134,7 +138,7 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< quiz: quizFetchedTimeString, }, miniSakaiLogo: chrome.extension.getURL("img/logo.png"), - VERSION: VERSION, + VERSION: config.version, subset: subset, noAssignment: noAssignmentImg, elements: { @@ -191,8 +195,8 @@ export function createMiniSakaiGeneralized(root: Element, assignmentList: Array< /** * Insert miniSakai into Sakai. */ -function createMiniSakai(assignmentList: Array, courseSiteInfos: Array): void { - createMiniSakaiGeneralized(miniSakai, assignmentList, courseSiteInfos, false, (rendered) => { +async function createMiniSakai(assignmentList: Array, courseSiteInfos: Array): Promise { + await createMiniSakaiGeneralized(miniSakai, assignmentList, courseSiteInfos, false, (rendered) => { miniSakai.innerHTML = rendered; const parent = document.getElementById("pageBody"); const ref = document.getElementById("toolMenuWrap"); @@ -204,18 +208,19 @@ function createMiniSakai(assignmentList: Array, courseSiteInfos: Arr * Initialize Settings tab. */ async function createSettingsTab(root: Element) { - 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"); + const config = await loadConfigs(); + createSettingItem(root, chrome.i18n.getMessage('settings_color_checked_item'), config.CPSettings.getDisplayCheckedAssignment, "displayCheckedAssignment"); + createSettingItem(root, chrome.i18n.getMessage('settings_display_late_submit_assignment'), config.CPSettings.getDisplayLateSubmitAssignment, "displayLateSubmitAssignment"); + createSettingItem(root, chrome.i18n.getMessage('settings_assignment_cache'), config.CPSettings.getAssignmentCacheInterval, "assignmentCacheInterval"); + createSettingItem(root, chrome.i18n.getMessage('settings_quizzes_cache'), config.CPSettings.getQuizCacheInterval, "quizCacheInterval"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['1', 24]), CPsettings.getTopColorDanger, "topColorDanger"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 5]), CPsettings.getTopColorWarning, "topColorWarning"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 14]), CPsettings.getTopColorSuccess, "topColorSuccess"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['1', 24]), config.CPSettings.getTopColorDanger, "topColorDanger"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 5]), config.CPSettings.getTopColorWarning, "topColorWarning"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 14]), config.CPSettings.getTopColorSuccess, "topColorSuccess"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['2', 24]), CPsettings.getMiniColorDanger, "miniColorDanger"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 5]), CPsettings.getMiniColorWarning, "miniColorWarning"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 14]), CPsettings.getMiniColorSuccess, "miniColorSuccess"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['2', 24]), config.CPSettings.getMiniColorDanger, "miniColorDanger"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 5]), config.CPSettings.getMiniColorWarning, "miniColorWarning"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 14]), config.CPSettings.getMiniColorSuccess, "miniColorSuccess"); createSettingItem(root, chrome.i18n.getMessage("settings_reset_colors"), "reset", "reset"); // @ts-ignore @@ -293,13 +298,14 @@ function initState(root: Element) { * Display miniSakai */ async function displayMiniSakai(mergedAssignmentList: Array, courseSiteInfos: Array): Promise{ - createMiniSakai(mergedAssignmentList, courseSiteInfos); + await createMiniSakai(mergedAssignmentList, courseSiteInfos); } /** * Add notification badge for new Assignment/Quiz */ -function createFavoritesBarNotification(courseSiteInfos: Array, assignmentList: Array): void { +async function createFavoritesBarNotification(courseSiteInfos: Array, assignmentList: Array): Promise { + const config = await loadConfigs(); const defaultTab = document.querySelectorAll(".Mrphs-sitesNav__menuitem"); const defaultTabCount = Object.keys(defaultTab).length; @@ -312,7 +318,7 @@ function createFavoritesBarNotification(courseSiteInfos: Array, return assignment.courseSiteInfo.courseID === courseID; }); if (q !== -1) { - const closestTime = (CPsettings.displayCheckedAssignment) ? assignmentList[q].closestDueDateTimestamp : assignmentList[q].closestDueDateTimestampExcludeFinished; + const closestTime = (config.CPSettings.displayCheckedAssignment) ? assignmentList[q].closestDueDateTimestamp : assignmentList[q].closestDueDateTimestampExcludeFinished; if (!assignmentList[q].isRead && closestTime !== -1) { defaultTab[j].classList.add("cs-notification-badge"); } @@ -348,7 +354,7 @@ function createFavoritesBarNotification(courseSiteInfos: Array, } } } - overrideCSSColor(); + await overrideCSSColor(); } /** @@ -369,7 +375,8 @@ function deleteFavoritesBarNotification(): void { /** * Override CSS of favorites bar and miniSakai. */ -function overrideCSSColor() { +async function overrideCSSColor() { + const config = await loadConfigs(); const overwriteborder = function (className: string, color: string | undefined) { const element = document.getElementsByClassName(className); for (let i = 0; i < element.length; i++) { @@ -390,18 +397,18 @@ function overrideCSSColor() { }; // Overwrite colors - overwritebackground("cs-course-danger", CPsettings.getMiniColorDanger); - overwritebackground("cs-course-warning", CPsettings.getMiniColorWarning); - overwritebackground("cs-course-success", CPsettings.getMiniColorSuccess); - overwritebackground("cs-tab-danger", CPsettings.getTopColorDanger); - overwritebackground("cs-tab-warning", CPsettings.getTopColorWarning); - overwritebackground("cs-tab-success", CPsettings.getTopColorSuccess); - overwriteborder("cs-assignment-danger", CPsettings.getMiniColorDanger); - overwriteborder("cs-assignment-warning", CPsettings.getMiniColorWarning); - overwriteborder("cs-assignment-success", CPsettings.getMiniColorSuccess); - overwriteborder("cs-tab-danger", CPsettings.getTopColorDanger); - overwriteborder("cs-tab-warning", CPsettings.getTopColorWarning); - overwriteborder("cs-tab-success", CPsettings.getTopColorSuccess); + overwritebackground("cs-course-danger", config.CPSettings.getMiniColorDanger); + overwritebackground("cs-course-warning", config.CPSettings.getMiniColorWarning); + overwritebackground("cs-course-success", config.CPSettings.getMiniColorSuccess); + overwritebackground("cs-tab-danger", config.CPSettings.getTopColorDanger); + overwritebackground("cs-tab-warning", config.CPSettings.getTopColorWarning); + overwritebackground("cs-tab-success", config.CPSettings.getTopColorSuccess); + overwriteborder("cs-assignment-danger", config.CPSettings.getMiniColorDanger); + overwriteborder("cs-assignment-warning", config.CPSettings.getMiniColorWarning); + overwriteborder("cs-assignment-success", config.CPSettings.getMiniColorSuccess); + overwriteborder("cs-tab-danger", config.CPSettings.getTopColorDanger); + overwriteborder("cs-tab-warning", config.CPSettings.getTopColorWarning); + overwriteborder("cs-tab-success", config.CPSettings.getTopColorSuccess); } export { diff --git a/src/subsakai.ts b/src/subsakai.ts index b86dbee..58cf4eb 100644 --- a/src/subsakai.ts +++ b/src/subsakai.ts @@ -20,7 +20,7 @@ async function updateSubSakai(root: Element) { mergedAssignmentList = mergeIntoAssignmentList(mergedAssignmentList, assignmentMemoList); mergedAssignmentList = sortAssignmentList(mergedAssignmentList); - createMiniSakaiGeneralized(root, mergedAssignmentList, courseIDs, true, (rendered) => { + await createMiniSakaiGeneralized(root, mergedAssignmentList, courseIDs, true, (rendered) => { console.log(rendered); root.innerHTML = rendered; }); From e31bf0c90b13c72e976a5df0440163a4879a615c Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:48:34 +0900 Subject: [PATCH 07/10] delete unused lines --- src/content_script.ts | 23 +---------------------- src/eventListener.ts | 4 +--- src/minisakai.ts | 4 ---- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/content_script.ts b/src/content_script.ts index 415837e..30ef3c9 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -1,6 +1,6 @@ import { loadFromLocalStorage, saveToLocalStorage } from "./storage"; import { Assignment, CourseSiteInfo } from "./model"; -import { getCourseIDList, getBaseURL, getAssignmentByCourseID, getQuizFromCourseID } from "./network"; +import { getCourseIDList, getAssignmentByCourseID, getQuizFromCourseID } from "./network"; import { createMiniSakaiBtn, createFavoritesBarNotification, displayMiniSakai } from "./minisakai"; import { @@ -16,14 +16,6 @@ import { } from "./utils"; import { Config, loadConfigs } from "./settings"; -// export const baseURL = getBaseURL(); -// export const VERSION = chrome.runtime.getManifest().version; -// export let assignmentFetchedTime: number | undefined; -// export let quizFetchedTime: number | undefined; -// export let assignmentCacheInterval: number; -// export let quizCacheInterval: number; -// export let CPsettings: Settings; - export let courseIDList: Array; export let mergedAssignmentList: Array; export let mergedAssignmentListNoMemo: Array; @@ -105,18 +97,6 @@ export async function loadAndMergeAssignmentList(config: Config ,courseSiteInfos return mergedAssignmentList; } -// /** -// * Load configurations from local storage -// */ -// async function loadConfigs() { -// CPsettings = await loadSettings(); -// assignmentCacheInterval = CPsettings.getAssignmentCacheInterval; -// quizCacheInterval = CPsettings.getQuizCacheInterval; -// CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment; -// assignmentFetchedTime = await loadFromLocalStorage("CS_AssignmentFetchTime", "undefined"); -// quizFetchedTime = await loadFromLocalStorage("CS_QuizFetchTime", "undefined"); -// } - /** * Load course site IDs */ @@ -129,7 +109,6 @@ async function main() { if (isLoggedIn()) { createMiniSakaiBtn(); const config = await loadConfigs(); - console.log("config", config,useCache(config.fetchedTime.assignment, config.cacheInterval.assignment),useCache(config.fetchedTime.quiz, config.cacheInterval.quiz)) await loadCourseIDList(); mergedAssignmentList = await loadAndMergeAssignmentList( config, diff --git a/src/eventListener.ts b/src/eventListener.ts index f9f13d9..bc13ef0 100644 --- a/src/eventListener.ts +++ b/src/eventListener.ts @@ -126,7 +126,6 @@ async function toggleFinishedFlag(event: any): Promise { async function updateSettings(event: any, type: string): Promise { const settingsID = event.target.id; let settingsValue = event.target.value; - // console.log("Settings...", settingsID, settingsValue,event.target.value) const config = await loadConfigs(); const CPSettings = config.CPSettings; @@ -161,8 +160,7 @@ async function updateSettings(event: any, type: string): Promise { CPSettings[settingsID] = settingsValue; } - saveToLocalStorage("CS_Settings", CPSettings); - console.log("CPSettings", CPSettings); + await saveToLocalStorage("CS_Settings", CPSettings); await redrawFavoritesBar(courseIDList, true); } diff --git a/src/minisakai.ts b/src/minisakai.ts index d4e1e0d..07c4516 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -1,7 +1,6 @@ import { Assignment, CourseSiteInfo, DisplayAssignment, DisplayAssignmentEntry } from "./model"; import { createCourseIDMap, getDaysUntil, formatTimestamp, nowTime } from "./utils"; import { appendChildAll, cloneElem, hamburger, miniSakai, SettingsDom } from "./dom"; -// import { CPsettings, assignmentFetchedTime, quizFetchedTime, VERSION } from "./content_script"; import { addMemo, deleteMemo, @@ -33,11 +32,8 @@ function createMiniSakaiBtn(): void { */ export async function createMiniSakaiGeneralized(root: Element, assignmentList: Array, courseSiteInfos: Array, subset: boolean, insertionProcess: (rendered: string) => void): Promise { const config = await loadConfigs(); - console.log("minisakai config", config) const assignmentFetchedTimeString = formatTimestamp(config.fetchedTime.assignment); const quizFetchedTimeString = formatTimestamp(config.fetchedTime.quiz); - console.log("timestamps", assignmentFetchedTimeString, quizFetchedTimeString) - const courseSiteList: Array = []; const courseIDMap = createCourseIDMap(courseSiteInfos); From 093d97a26fa3e6ceb84de597faa24da35323f12e Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:52:20 +0900 Subject: [PATCH 08/10] renamed `CPsetting` to `CSsetting` --- src/eventListener.ts | 8 ++++---- src/minisakai.ts | 48 ++++++++++++++++++++++---------------------- src/settings.ts | 18 ++++++++--------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/eventListener.ts b/src/eventListener.ts index bc13ef0..ae9628f 100644 --- a/src/eventListener.ts +++ b/src/eventListener.ts @@ -127,7 +127,7 @@ async function updateSettings(event: any, type: string): Promise { const settingsID = event.target.id; let settingsValue = event.target.value; const config = await loadConfigs(); - const CPSettings = config.CPSettings; + const CSsettings = config.CSsettings; // Type of Settings switch (type) { @@ -148,7 +148,7 @@ async function updateSettings(event: any, type: string): Promise { ]; for (const k of colorList) { // @ts-ignore - CPSettings[k] = DefaultSettings[k]; + CSsettings[k] = DefaultSettings[k]; const q = document.getElementById(k); if (q) { // @ts-ignore @@ -157,10 +157,10 @@ async function updateSettings(event: any, type: string): Promise { } } else { // @ts-ignore - CPSettings[settingsID] = settingsValue; + CSsettings[settingsID] = settingsValue; } - await saveToLocalStorage("CS_Settings", CPSettings); + await saveToLocalStorage("CS_Settings", CSsettings); await redrawFavoritesBar(courseIDList, true); } diff --git a/src/minisakai.ts b/src/minisakai.ts index 07c4516..122c2c9 100644 --- a/src/minisakai.ts +++ b/src/minisakai.ts @@ -90,7 +90,7 @@ export async function createMiniSakaiGeneralized(root: Element, assignmentList: appendElement(courseName, otherElements); break; case "duePassed": - const showLateSubmitAssignment = config.CPSettings ? config.CPSettings.getDisplayLateSubmitAssignment : false; + const showLateSubmitAssignment = config.CSsettings ? config.CSsettings.getDisplayLateSubmitAssignment : false; if (showLateSubmitAssignment && getDaysUntil(nowTime, assignmentEntry.getCloseDateTimestamp * 1000) !== "duePassed") { appendElement(courseName, lateSubmitElements); } @@ -205,18 +205,18 @@ async function createMiniSakai(assignmentList: Array, courseSiteInfo */ async function createSettingsTab(root: Element) { const config = await loadConfigs(); - createSettingItem(root, chrome.i18n.getMessage('settings_color_checked_item'), config.CPSettings.getDisplayCheckedAssignment, "displayCheckedAssignment"); - createSettingItem(root, chrome.i18n.getMessage('settings_display_late_submit_assignment'), config.CPSettings.getDisplayLateSubmitAssignment, "displayLateSubmitAssignment"); - createSettingItem(root, chrome.i18n.getMessage('settings_assignment_cache'), config.CPSettings.getAssignmentCacheInterval, "assignmentCacheInterval"); - createSettingItem(root, chrome.i18n.getMessage('settings_quizzes_cache'), config.CPSettings.getQuizCacheInterval, "quizCacheInterval"); + createSettingItem(root, chrome.i18n.getMessage('settings_color_checked_item'), config.CSsettings.getDisplayCheckedAssignment, "displayCheckedAssignment"); + createSettingItem(root, chrome.i18n.getMessage('settings_display_late_submit_assignment'), config.CSsettings.getDisplayLateSubmitAssignment, "displayLateSubmitAssignment"); + createSettingItem(root, chrome.i18n.getMessage('settings_assignment_cache'), config.CSsettings.getAssignmentCacheInterval, "assignmentCacheInterval"); + createSettingItem(root, chrome.i18n.getMessage('settings_quizzes_cache'), config.CSsettings.getQuizCacheInterval, "quizCacheInterval"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['1', 24]), config.CPSettings.getTopColorDanger, "topColorDanger"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 5]), config.CPSettings.getTopColorWarning, "topColorWarning"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 14]), config.CPSettings.getTopColorSuccess, "topColorSuccess"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['1', 24]), config.CSsettings.getTopColorDanger, "topColorDanger"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 5]), config.CSsettings.getTopColorWarning, "topColorWarning"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['1', 14]), config.CSsettings.getTopColorSuccess, "topColorSuccess"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['2', 24]), config.CPSettings.getMiniColorDanger, "miniColorDanger"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 5]), config.CPSettings.getMiniColorWarning, "miniColorWarning"); - createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 14]), config.CPSettings.getMiniColorSuccess, "miniColorSuccess"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_hour', ['2', 24]), config.CSsettings.getMiniColorDanger, "miniColorDanger"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 5]), config.CSsettings.getMiniColorWarning, "miniColorWarning"); + createSettingItem(root, chrome.i18n.getMessage('settings_colors_day', ['2', 14]), config.CSsettings.getMiniColorSuccess, "miniColorSuccess"); createSettingItem(root, chrome.i18n.getMessage("settings_reset_colors"), "reset", "reset"); // @ts-ignore @@ -314,7 +314,7 @@ async function createFavoritesBarNotification(courseSiteInfos: Array { const settingsArr = await loadFromLocalStorage("CS_Settings"); - const CPsettings = convertArrayToSettings(settingsArr); - CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment; - return CPsettings; + const CSsettings = convertArrayToSettings(settingsArr); + CSsettings.displayCheckedAssignment = CSsettings.getDisplayCheckedAssignment; + return CSsettings; } export interface Config { baseURL: string; version: string; - CPSettings: Settings; + CSsettings: Settings; fetchedTime: { assignment: number; quiz: number; @@ -93,16 +93,16 @@ export interface Config { export async function loadConfigs(): Promise { const baseURL = getBaseURL(); const VERSION = chrome.runtime.getManifest().version; - const CPsettings = await loadSettings(); - CPsettings.displayCheckedAssignment = CPsettings.getDisplayCheckedAssignment; - const assignmentCacheInterval = CPsettings.getAssignmentCacheInterval; - const quizCacheInterval = CPsettings.getQuizCacheInterval; + const CSsettings = await loadSettings(); + CSsettings.displayCheckedAssignment = CSsettings.getDisplayCheckedAssignment; + const assignmentCacheInterval = CSsettings.getAssignmentCacheInterval; + const quizCacheInterval = CSsettings.getQuizCacheInterval; const assignmentFetchedTime = await loadFromLocalStorage("CS_AssignmentFetchTime", "undefined"); const quizFetchedTime = await loadFromLocalStorage("CS_QuizFetchTime", "undefined"); return { baseURL: baseURL, version: VERSION, - CPSettings: CPsettings, + CSsettings: CSsettings, cacheInterval: { assignment: assignmentCacheInterval, quiz: quizCacheInterval, From a65fe80150bfe04b9d665b5f3224edbbabfb7c11 Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:55:53 +0900 Subject: [PATCH 09/10] v1.2.1 --- README.md | 6 +++--- manifest.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 817ba66..c38dbd6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Colors course site tabs according to the assignment due date. Due date within 14 Days ## Notification Badge -Tells your unchecked latest assignments. +Tells your **unchecked** latest assignments. Notification badge will appear in the upper left-hand side of a course site tab. If you open a course site with the notification badge on, the badge will disappear. @@ -50,8 +50,8 @@ You can add your custom assignment to miniSakai as `memo` with PLUS button locat Also check box is available for you to distinguish completed assignments from working assignments. ## Cache -In order to reduce the network load on Sakai LMS, we have implemented a cache function for getting assignments and quizzes from REST API. -The default cache interval is as follows +In order to reduce the network load on Sakai LMS, we have implemented a cache function for fetching assignments and quizzes from REST API. +The default cache interval is as follows: - Assignment fetching --- 2 minutes - Quiz fetching --- 10 minutes diff --git a/manifest.json b/manifest.json index 3f0de5f..0dfcad6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Comfortable Sakai", "description": "__MSG_EXTENSION_DESCRIPTION__", - "version": "1.2.0", + "version": "1.2.1", "manifest_version": 2, "default_locale": "en", "icons": { diff --git a/package.json b/package.json index ca76a43..217275b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "comfortable-sakai", "version": "1.1.0", - "description": "Comfortable Sakai is a browser extension for managing assignments and quizzes on Sakai LMS.", + "description": "Comfortable Sakai is a Web browser extension for managing assignments and quizzes on Sakai LMS.", "main": "index.ts", "scripts": { "test": "jest", From 0369b28962c823fdd0dfa5c41c1271392b795bb3 Mon Sep 17 00:00:00 2001 From: das08 Date: Wed, 12 Jan 2022 14:56:56 +0900 Subject: [PATCH 10/10] delete console.log --- src/content_script.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content_script.ts b/src/content_script.ts index 30ef3c9..e817e9b 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -76,7 +76,6 @@ export async function loadAndMergeAssignmentList(config: Config ,courseSiteInfos } // Update assignment fetch timestamp await saveToLocalStorage("CS_QuizFetchTime", nowTime); - console.log("saved quiz fetch time") config.fetchedTime.quiz = nowTime; } // Compare quizzes with old ones