From dae79605b3b83ae74f6cdeff72e1bc3d857531e0 Mon Sep 17 00:00:00 2001 From: conlacda Date: Fri, 23 Aug 2024 23:15:50 +0900 Subject: [PATCH] update: refactor --- .../scripts/mark-solved-problem/main.js | 4 ++-- .../scripts/mark-solved-problem/utils.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/browser-extension/chrome-extension/scripts/mark-solved-problem/main.js b/browser-extension/chrome-extension/scripts/mark-solved-problem/main.js index 760865e..a04ad6c 100644 --- a/browser-extension/chrome-extension/scripts/mark-solved-problem/main.js +++ b/browser-extension/chrome-extension/scripts/mark-solved-problem/main.js @@ -29,7 +29,7 @@ currentSessionLastUpdate = submission.time; } - if (Submission.isJudging(submission.status)) { + if (isJudging(submission.status)) { currentSessionLastUpdate = submission.time; } @@ -53,7 +53,7 @@ addStatusColumnToTable(submissionStt); // Discard WJ, JD then store to local storge. WJ, JD just are for showing in the current session not persistent. for (const [task, submission] of Object.entries(submissionStt)) { - if (Submission.isJudging(submission.status)) + if (isJudging(submission.status)) delete submissionStt[task]; } await writeLocalStorage(lastUpdateKey, currentSessionLastUpdate); diff --git a/browser-extension/chrome-extension/scripts/mark-solved-problem/utils.js b/browser-extension/chrome-extension/scripts/mark-solved-problem/utils.js index dec2714..88e9540 100644 --- a/browser-extension/chrome-extension/scripts/mark-solved-problem/utils.js +++ b/browser-extension/chrome-extension/scripts/mark-solved-problem/utils.js @@ -1,5 +1,5 @@ /** - * Check if the provided HTML contains a next page link. + * Check if there is the next submission page or not. * @param {string} pageContent - The HTML content of the current page. * @returns {boolean} Returns true if the HTML contains a next page link, otherwise false. */ @@ -64,8 +64,13 @@ class Submission { this.memory = isWJOrCE ? 0 : tds.eq(8).text(); this.detail = isWJOrCE ? tds.eq(7).find('a:first').href : tds.eq(9).find('a:first').href; } +} - static isJudging(status) { - return status === 'WJ' || status === 'JD' || status.includes('/'); - } +/** + * Check if a submission is judging or not + * @param {string} stats - A submission's status + * @returns {boolean} + */ +const isJudging = (status) => { + return status === 'WJ' || status === 'JD' || status.includes('/'); }