diff --git a/background_script/background.js b/background_script/background.js index cb38287..8547323 100644 --- a/background_script/background.js +++ b/background_script/background.js @@ -1,24 +1,29 @@ console.log("background.js"); importScripts("api.js"); importScripts("helpui.js"); - - - function grade_teammates(params, privateCqId, classroomSessionId, groupId) { - console.log(params); - + // console.log(params); + // console.log( // format_grade_teammates(params, privateCqId, classroomSessionId, groupId) // ); - - - console.log(params); + // console.log(params); const ans = post_api({ url: `https://fugw-edunext.fpt.edu.vn:${PORT}/api/v1/grade/grade-teammates`, - body: {"gradeTeammatesList":format_grade_teammates(params, privateCqId, classroomSessionId, groupId)}, + body: { + gradeTeammatesList: format_grade_teammates( + params, + privateCqId, + classroomSessionId, + groupId + ), + }, }); ans - .then((data) => {}) + .then((data) => { + console.log(data) + + }) .catch((e) => { console.log(e); }); @@ -26,7 +31,7 @@ function grade_teammates(params, privateCqId, classroomSessionId, groupId) { function get_grade(params) { // param = {"privateCqId":privateCqId,"sessionId":sessionId,"groupId":groupID} - + const ans = post_api({ url: `https://fugw-edunext.fpt.edu.vn:${PORT}/api/v1/grade/get-grade`, body: { @@ -38,16 +43,17 @@ function get_grade(params) { .then((data) => { if (data.data.gradeResponseList.length != 0) { // console.log(params.privateCqId, params.sessionId, params.groupId); - console.log(data.data); - + // console.log(data.data); + privateCqId = params.privateCqId; sessionId = params.sessionId; groupId = params.groupId; grade_teammates( data.data.gradeResponseList, - privateCqId,sessionId, groupId + privateCqId, + sessionId, + groupId ); - } }) .catch((e) => { @@ -94,11 +100,10 @@ function list_group() { // console.log(element3); get_grade({ - "privateCqId": privateCqId, - "sessionId": sessionId, - "groupId": groupID, + privateCqId: privateCqId, + sessionId: sessionId, + groupId: groupID, }); - } // Iterate over the students in the current group. @@ -213,24 +218,21 @@ chrome.webRequest.onBeforeSendHeaders.addListener( console.log(USER_INFOR); subjects_in_the_semester("DEFAULT"); - chrome.runtime.sendMessage({type: 'popup', message: "hello vietnam"}, function(response) { - console.log('Received response from background:', response); - }); + // send mess from background script to popup script + messtopopup({ type: "background", message: USER_INFOR }); + //send mess from background script to content script + messtocontent(details,token) + }) .catch((e) => { console.log(e.message); }); - chrome.tabs.sendMessage(details.tabId, { - token: token, - details: details, - }); + } }, { - urls: ["https://fugw-edunext.fpt.edu.vn:8443/api/auth/token"], + urls: [`https://fugw-edunext.fpt.edu.vn:${PORT}/api/auth/token`], }, ["requestHeaders"] ); - - diff --git a/background_script/helpui.js b/background_script/helpui.js index afab5cf..4761899 100644 --- a/background_script/helpui.js +++ b/background_script/helpui.js @@ -1,30 +1,24 @@ -console.log("helpui.js") -function check_course_list(params) { - var boolean = false; - - USER_COURSE.forEach(element => { - if (element.id == params) - { - boolean = true; - } - }) - return boolean; - } - +function check_course_list(params) { + var boolean = false; + USER_COURSE.forEach((element) => { + if (element.id == params) { + boolean = true; + } + }); + return boolean; +} - // convert questions to json +// convert questions to json function question_format(params) { + for (let i = 0; i < params.length; i++) { + const element = params[i]; + params[i].questions = JSON.parse(element.questions); + } - for (let i = 0; i < params.length; i++) { - const element = params[i]; - params[i].questions = JSON.parse(element.questions); - } - - return params; + return params; } - function check_group_user(params) { var boolean = false; params.listStudentByGroups.forEach((element) => { @@ -42,24 +36,67 @@ function format_grade_teammates( classroomSessionId, groupId ) { - console.log(params); - console.log(privateCqId, classroomSessionId,groupId); + // console.log(params); + // console.log(privateCqId, classroomSessionId, groupId); var teamlist = params; var newParams = []; - console.log(params); + for (let index = 0; index < teamlist.length; index++) { newParams.push({ - "id": teamlist[index].id, - "hardWorking": 5, - "goodKnowledge": 5, - "teamWorking": 5, - "userIsGraded": teamlist[index].userIsGraded ? teamlist[index].userIsGraded : 0, - "groupId": groupId ? groupId : 0, - "privateCqId": privateCqId, - "classroomSessionId": teamlist[index].classroomSessionId ? teamlist[index].classroomSessionId : 0, - "userIsGradedId": teamlist[index].userIsGraded ? teamlist[index].userIsGraded : 0, + id: teamlist[index].id, + hardWorking: 5, + goodKnowledge: 5, + teamWorking: 5, + userIsGraded: teamlist[index].userIsGraded + ? teamlist[index].userIsGraded + : 0, + groupId: groupId ? groupId : 0, + privateCqId: privateCqId, + classroomSessionId: teamlist[index].classroomSessionId + ? teamlist[index].classroomSessionId + : 0, + userIsGradedId: teamlist[index].userIsGraded + ? teamlist[index].userIsGraded + : 0, }); - }; + } // console.log(newParams); return newParams; -} \ No newline at end of file +} + +// declare mess to post to popup script +function messtopopup(params) { + chrome.runtime.sendMessage({ + message: params.message, + type: params.type, + }); +} +// declare mess to post to popup script +function messtocontent(params, token) { + chrome.tabs.sendMessage(params.tabId, { + token: token, + details: params, + }); +} + + +// background script listen message from popup script and content script +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { + console.log(request); + if(request.type == 'content_to_background') { + + const ans = post_api({url: `https://fugw-edunext.fpt.edu.vn:${PORT}/api/auth/token`}) + ans.then((data) => { + console.log(data) + messtopopup({type: "background", message: data.data}) + }) + } + if(request.type == 'popup_to_background') { + + const ans = post_api({url: `https://fugw-edunext.fpt.edu.vn:${PORT}/api/auth/token`}) + ans.then((data) => { + console.log(data) + messtopopup({type: "background", message: data.data}) + }) + } +}) diff --git a/content/content.js b/content/content.js index f320cd7..d2db0b3 100644 --- a/content/content.js +++ b/content/content.js @@ -1,14 +1,20 @@ -console.log("some thing here") +console.log("content script is running") // Listen for messages from the content script -TOKEN = "123"; -function logMessage(message) { - console.log(message) - -} +function sendmess(params) { + console.log(params) + chrome.runtime.sendMessage( + params +)} +function logMessage(message) { + console.log(message) + token = localStorage.getItem("token") + console.log(`this is token: ${token}`) + sendmess({type: "content_to_background", data: token}) +} chrome.runtime.onMessage.addListener( (request, sender, sendResponse) => { diff --git a/popup/active_page.js b/popup/active_page.js index acf070e..03a800d 100644 --- a/popup/active_page.js +++ b/popup/active_page.js @@ -29,8 +29,37 @@ chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => { }) let url = tabs[0].url; - if (!url.includes('https://fu-edunext.fpt.edu.vn/')) { - document.getElementById('container').innerHTML = '
Email: ${USER_INFOR.email} + // Name: ${USER_INFOR.name} + // RollNumber: ${USER_INFOR.rollNumber} + //
`; + // } else { + // document.getElementById("container").innerHTML = 'Email: ${USER_INFOR.email} + Name: ${USER_INFOR.name} + RollNumber: ${USER_INFOR.rollNumber} +
`; + } else { + document.getElementById("container").innerHTML = + '