diff --git a/src/scripts/emailClientAdapter.js b/src/scripts/emailClientAdapter.js index 5927e78..cfb88ff 100644 --- a/src/scripts/emailClientAdapter.js +++ b/src/scripts/emailClientAdapter.js @@ -77,19 +77,16 @@ class EmailClientAdapter { // Helper method to injectContent dispatchElementEvents(element, events, includeKeyboard = false) { if (!element || !events) return; - const eventsToDispatch = Array.isArray(events) ? events : [events]; - - eventsToDispatch.forEach((eventType) => { + for (const eventType of eventsToDispatch) { // Dispatch standard events element.dispatchEvent(new Event(eventType, { bubbles: true })); - // Dispatch keyboard events if needed if (includeKeyboard) { element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true })); element.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true })); } - }); + } } injectContent(element, content, eventType) { @@ -99,17 +96,16 @@ class EmailClientAdapter { } const clientType = this.detectClient(); const config = this.clientConfigs[clientType]; - try { switch (config?.injectMethod) { - case 'focusAndPaste': + case 'focusAndPaste': { // Special handling for Outlook element.focus(); element.innerHTML = content; this.dispatchElementEvents(element, ['input', 'change'], true); break; - - case 'setContent': + } + case 'setContent': { // Special handling for Yahoo element.innerHTML = content; element.focus(); @@ -121,11 +117,12 @@ class EmailClientAdapter { selection.addRange(range); this.dispatchElementEvents(element, ['input', 'change']); break; - - default: + } + default: { // Default handling for Google clients element.innerHTML = content; element.dispatchEvent(new Event(eventType, { bubbles: true })); + } } return true; } catch (error) { diff --git a/src/scripts/main.js b/src/scripts/main.js index f1ff385..65a431a 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,13 +1,13 @@ /* global $,Materialize*/ -var enableToggleElement = document.getElementById('enable'); -var githubUsernameElement = document.getElementById('githubUsername'); -var projectNameElement = document.getElementById('projectName'); -var lastWeekContributionElement = document.getElementById('lastWeekContribution'); -var startingDateElement = document.getElementById('startingDate'); -var endingDateElement = document.getElementById('endingDate'); -var showOpenLabelElement = document.getElementById('showOpenLabel'); -var userReasonElement = document.getElementById('userReason'); -var gsoc = 0; //0 means gsoc. 1 means gsoc +const enableToggleElement = document.getElementById('enable'); +const githubUsernameElement = document.getElementById('githubUsername'); +const projectNameElement = document.getElementById('projectName'); +const lastWeekContributionElement = document.getElementById('lastWeekContribution'); +const startingDateElement = document.getElementById('startingDate'); +const endingDateElement = document.getElementById('endingDate'); +const showOpenLabelElement = document.getElementById('showOpenLabel'); +const userReasonElement = document.getElementById('userReason'); +let gsoc = 0; //0 means gsoc. 1 means gsoc function handleBodyOnLoad() { // prefill name chrome.storage.local.get( @@ -60,7 +60,7 @@ function handleBodyOnLoad() { lastWeekContributionElement.checked = true; handleLastWeekContributionChange(); } - if (items.gsoc == 1) { + if (items.gsoc === 1) { handleGsocClick(); } else { handleCodeheatClick(); @@ -69,19 +69,19 @@ function handleBodyOnLoad() { ); } function handleEnableChange() { - var value = enableToggleElement.checked; + const value = enableToggleElement.checked; chrome.storage.local.set({ enableToggle: value }); } function handleStartingDateChange() { - var value = startingDateElement.value; + const value = startingDateElement.value; chrome.storage.local.set({ startingDate: value }); } function handleEndingDateChange() { - var value = endingDateElement.value; + const value = endingDateElement.value; chrome.storage.local.set({ endingDate: value }); } function handleLastWeekContributionChange() { - var value = lastWeekContributionElement.checked; + const value = lastWeekContributionElement.checked; if (value) { startingDateElement.disabled = true; endingDateElement.disabled = true; @@ -95,51 +95,43 @@ function handleLastWeekContributionChange() { } chrome.storage.local.set({ lastWeekContribution: value }); } -function getLastWeek() { - var today = new Date(); - var noDays_to_goback = gsoc == 0 ? 7 : 1; - var lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDays_to_goback); - var lastWeekMonth = lastWeek.getMonth() + 1; - var lastWeekDay = lastWeek.getDate(); - var lastWeekYear = lastWeek.getFullYear(); - var lastWeekDisplayPadded = - ('0000' + lastWeekYear.toString()).slice(-4) + - '-' + - ('00' + lastWeekMonth.toString()).slice(-2) + - '-' + - ('00' + lastWeekDay.toString()).slice(-2); - return lastWeekDisplayPadded; +function getLastWeek(gsoc) { + const today = new Date(); + const noDays_to_goback = gsoc === 0 ? 7 : 1; + const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDays_to_goback); + + const lastWeekYear = lastWeek.getFullYear(); + const lastWeekMonth = String(lastWeek.getMonth() + 1).padStart(2, '0'); + const lastWeekDay = String(lastWeek.getDate()).padStart(2, '0'); + + return `${lastWeekYear}-${lastWeekMonth}-${lastWeekDay}`; } + function getToday() { - var today = new Date(); - var Week = new Date(today.getFullYear(), today.getMonth(), today.getDate()); - var WeekMonth = Week.getMonth() + 1; - var WeekDay = Week.getDate(); - var WeekYear = Week.getFullYear(); - var WeekDisplayPadded = - ('0000' + WeekYear.toString()).slice(-4) + - '-' + - ('00' + WeekMonth.toString()).slice(-2) + - '-' + - ('00' + WeekDay.toString()).slice(-2); + const today = new Date(); + const Week = new Date(today.getFullYear(), today.getMonth(), today.getDate()); + const WeekMonth = Week.getMonth() + 1; + const WeekDay = Week.getDate(); + const WeekYear = Week.getFullYear(); + const WeekDisplayPadded = `${(`0000${WeekYear.toString()}`).slice(-4)}-${(`00${WeekMonth.toString()}`).slice(-2)}-${(`00${WeekDay.toString()}`).slice(-2)}`; return WeekDisplayPadded; } function handleGithubUsernameChange() { - var value = githubUsernameElement.value; + const value = githubUsernameElement.value; chrome.storage.local.set({ githubUsername: value }); } function handleProjectNameChange() { - var value = projectNameElement.value; + const value = projectNameElement.value; chrome.storage.local.set({ projectName: value }); } function handleOpenLabelChange() { - var value = showOpenLabelElement.checked; + const value = showOpenLabelElement.checked; chrome.storage.local.set({ showOpenLabel: value }); chrome.storage.local.set({ showClosedLabel: value }); } function handleUserReasonChange() { - var value = userReasonElement.value; + const value = userReasonElement.value; chrome.storage.local.set({ userReason: value }); } function handleCodeheatClick() { diff --git a/src/scripts/scrumHelper.js b/src/scripts/scrumHelper.js index 785fab0..21b3eb8 100644 --- a/src/scripts/scrumHelper.js +++ b/src/scripts/scrumHelper.js @@ -1,37 +1,38 @@ -var refreshButton_Placed = false; -var enableToggle = true; +let refreshButtonPlaced = false; +let enableToggle = true; function allIncluded() { /* global $*/ - var scrumBody = null; - var scrumSubject = null; - var startingDate = ''; - var endingDate = ''; - var githubUsername = ''; - var projectName = ''; - var lastWeekArray = []; - var nextWeekArray = []; - var reviewedPrsArray = []; - var githubIssuesData = null; - var lastWeekContribution = false; - var githubPrsReviewData = null; - var githubUserData = null; - var githubPrsReviewDataProccessed = {}; - var showOpenLabel = true; - var showClosedLabel = true; - var userReason = ''; - var gsoc = 0; //0 means codeheat. 1 means gsoc - - var pr_merged_button = + let scrumBody = null; + let scrumSubject = null; + let startingDate = ''; + let endingDate = ''; + let githubUsername = ''; + let projectName = ''; + const lastWeekArray = []; + const nextWeekArray = []; + const reviewedPrsArray = []; + let githubIssuesData = null; + let lastWeekContribution = false; + let githubPrsReviewData = null; + let githubPrCommitsData = null; + let githubUserData = null; + const githubPrsReviewDataProccessed = {}; + let showOpenLabel = true; + let showClosedLabel = true; + let userReason = ''; + let gsoc = 0; //0 means codeheat. 1 means gsoc + + let prMergedButton = '
closed
'; - var pr_unmerged_button = + let prUnmergedButton = '
open
'; - var issue_closed_button = + let issueClosedButton = '
closed
'; - var issue_opened_button = + let issueOpenedButton = '
open
'; - var linkStyle = ''; + const linkStyle = ''; function getChromeData() { chrome.storage.local.get( [ @@ -60,31 +61,31 @@ function allIncluded() { if (!items.enableToggle) { enableToggle = items.enableToggle; } + if (items.projectName) { + projectName = items.projectName; + } if (items.endingDate && !lastWeekContribution) { endingDate = items.endingDate; } if (items.startingDate && !lastWeekContribution) { startingDate = items.startingDate; } + if (items.projectName) { + projectName = items.projectName; + } if (items.githubUsername) { githubUsername = items.githubUsername; fetchGithubData(); - } else { - console.warn('No GitHub username found in storage'); - } - if (items.projectName) { - projectName = items.projectName; } - if (!items.showOpenLabel) { showOpenLabel = false; - pr_unmerged_button = ''; - issue_opened_button = ''; + prUnmergedButton = ''; + issueOpenedButton = ''; } if (!items.showClosedLabel) { showClosedLabel = false; - pr_merged_button = ''; - issue_closed_button = ''; + prMergedButton = ''; + issueClosedButton = ''; } if (items.userReason) { userReason = items.userReason; @@ -102,89 +103,87 @@ function allIncluded() { startingDate = getLastWeek(); } function getLastWeek() { - var today = new Date(); - var noDays_to_goback = gsoc == 0 ? 7 : 1; - var lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDays_to_goback); - var lastWeekMonth = lastWeek.getMonth() + 1; - var lastWeekDay = lastWeek.getDate(); - var lastWeekYear = lastWeek.getFullYear(); - var lastWeekDisplayPadded = - ('0000' + lastWeekYear.toString()).slice(-4) + - '-' + - ('00' + lastWeekMonth.toString()).slice(-2) + - '-' + - ('00' + lastWeekDay.toString()).slice(-2); - return lastWeekDisplayPadded; + const today = new Date(); + const noDaysToGoBack = gsoc === 0 ? 7 : 1; + const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDaysToGoBack); + + const lastWeekYear = lastWeek.getFullYear().toString().padStart(4, '0'); + const lastWeekMonth = (lastWeek.getMonth() + 1).toString().padStart(2, '0'); + const lastWeekDay = lastWeek.getDate().toString().padStart(2, '0'); + + return `${lastWeekYear}-${lastWeekMonth}-${lastWeekDay}`; } + function getToday() { - var today = new Date(); - var Week = new Date(today.getFullYear(), today.getMonth(), today.getDate()); - var WeekMonth = Week.getMonth() + 1; - var WeekDay = Week.getDate(); - var WeekYear = Week.getFullYear(); - var WeekDisplayPadded = - ('0000' + WeekYear.toString()).slice(-4) + - '-' + - ('00' + WeekMonth.toString()).slice(-2) + - '-' + - ('00' + WeekDay.toString()).slice(-2); - return WeekDisplayPadded; + const today = new Date(); + + const WeekYear = today.getFullYear().toString().padStart(4, '0'); + const WeekMonth = (today.getMonth() + 1).toString().padStart(2, '0'); + const WeekDay = today.getDate().toString().padStart(2, '0'); + + return `${WeekYear}-${WeekMonth}-${WeekDay}`; } + // fetch github data function fetchGithubData() { - var issueUrl = - 'https://api.github.com/search/issues?q=author%3A' + - githubUsername + - '+org%3Afossasia+created%3A' + - startingDate + - '..' + - endingDate + - '&per_page=100'; + const issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}+org%3Afossasia+created%3A${startingDate}..${endingDate}&per_page=100`; + $.ajax({ dataType: 'json', type: 'GET', url: issueUrl, error: (xhr, textStatus, errorThrown) => { - // error + console.error('Error fetching GitHub issues:', textStatus, errorThrown); }, success: (data) => { githubIssuesData = data; }, }); - // fetch github prs review data - var prUrl = - 'https://api.github.com/search/issues?q=commenter%3A' + - githubUsername + - '+org%3Afossasia+updated%3A' + - startingDate + - '..' + - endingDate + - '&per_page=100'; + + // fetch GitHub PRs review data + const prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}+org%3Afossasia+updated%3A${startingDate}..${endingDate}&per_page=100`; $.ajax({ dataType: 'json', type: 'GET', url: prUrl, error: (xhr, textStatus, errorThrown) => { - // error + console.error('Error fetching GitHub PR reviews:', textStatus, errorThrown); }, success: (data) => { githubPrsReviewData = data; }, }); - // fetch github user data - var userUrl = 'https://api.github.com/users/' + githubUsername; + + // fetch GitHub user data + const userUrl = `https://api.github.com/users/${githubUsername}`; + $.ajax({ dataType: 'json', type: 'GET', url: userUrl, error: (xhr, textStatus, errorThrown) => { - // error + console.error('Error fetching GitHub user data:', textStatus, errorThrown); }, success: (data) => { githubUserData = data; }, }); + + // function to fetch commits in fossasia repos + const commitsUrl = `https://api.github.com/repos/fossasia/${projectName}/commits?author=${githubUsername}&since=${startingDate}T00:00:00Z&until=${endingDate}T23:59:59Z&per_page=100`; + + $.ajax({ + dataType: 'json', + type: 'GET', + url: commitsUrl, + error: (xhr, textStatus, errorThrown) => { + console.error('Error fetching commits from fossasia repos:', textStatus, errorThrown); + }, + success: (data) => { + githubPrCommitsData = data; + }, + }); } function formatDate(dateString) { @@ -199,22 +198,22 @@ function allIncluded() { setTimeout(() => { // Generate content first - var lastWeekUl = '