diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2ac17cd Binary files /dev/null and b/.DS_Store differ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3a4986 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +The extension is for facilitating grading and some data collections + You can download the extension here and unzip the zipfile, then + in the chrome extension page (chrome:/extensions), select "load unpacked" + and load the extension to your chrome extension browser. + Or you can find the extension in the chrome store (https://chrome.google.com/webstore/detail/feedback-prototype/nnkffffggnpbahijipfeddnmdbimobmb) + but it might not be the latest version, new version would be first pushed to github then update on + chrome store. + More detailed instructions on usage of the extension, please check this document: + https://docs.google.com/document/d/1QuesvGH1nJctrIWWKhP-Ob-SjBs2ZSGCzfVF6E4713U/edit?usp=sharing +And also checkout the instruction video online. + + +client id for online version: 66462531215-1prsgpfbnfl2mf88e27165g1vcv70pjl.apps.googleusercontent.com + +client id for debug ( in Zhaoyi's Macbook) here: +66462531215-mgror68snbk04d88ol3t4i7rnh0ul1j8.apps.googleusercontent.com + +If you would like to pull from this repo and do some debug in your local enviroment, remember to +register in google's API console or ask me to authenticate you in my console and get an client id for manifest.json. + +NOTICE: For first time users, if the chrome says the extension is unsafe, in that page, go to "advance" and let the chrome know you +will go unsafe. This extension is safe, this is not something you would like to see only in the chrome incognito mode. + diff --git a/background.js b/background.js index fcd506c..4c6dd9d 100644 --- a/background.js +++ b/background.js @@ -1,10 +1,50 @@ -var comment_sheet_id = "1-Xo0TcHNoSnbxtkGgiRcbnxcMip1R0PQFsrIOsiYevU"; -var event_sheet_id = "1pSgzEcft13sB3Lee_zNMkYD_WcDIUqKnjyP12XtLjzc"; +//W16-A10 is the comment sheet name used +//A10 is the event sheet name used +//NOTICE: make headings first for the table(A1:L1 for comment sheet) then do the insertions!! +//otherwise, table range will be a mess +var comment_sheet_id = "1YYVkmMhcgg-UvtntZ88e_nMiST5VGdipj7TVHZKD_qg"; +var event_sheet_id = "18aitRp5Bubiuapjo_pMeV6EE0Ixv3yE8zrli3y7QPx4"; var user_id; var always_show; var on_grading_page; +var store_rubric_item; +var last_row=1;//fetch the last row in the spreadsheets, used for the id field + +//UPDATE: here is some number magic here to auto refresh the page when you go to the next +//page for grading(by pressing Z or click next ungraded), +//refreshing the page by adding new rubric items/press refresh in chromewon't cause unstoppable refresh +//as I said, it's number magic, so I can't gurantee it works smoothly for everyone's chrome +//I will push this change to github but as for now, I won't add this as an update to extension in +//chrome store +var log_time=0 +var old_url="" +chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { + let tab_url=tab.url + + if(tab_url.indexOf("submissions")>0 && tab_url.indexOf("not_grouped")==-1){ + log_time++ + console.log(log_time) + let url_arr=tab_url.split("/") + let temp_num=url_arr[url_arr.length-2] + //if(log_time==3){ + if(log_time%3==0){ + console.log(old_url) + //log_time=log_time-6 + if(old_url!==temp_num){ + old_url=temp_num + console.log(log_time) + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.reload(tabs[0].id); + }); + } + } + } +}); + + function loadSpreadsheet() { + console.log("loadding spreadsheet now.....") if (chrome.identity === undefined) { console.log("Please sign-in to Chrome from its top-right menu."); return; @@ -32,13 +72,25 @@ function loadSpreadsheet() { }; xhr.open("GET", - "https://sheets.googleapis.com/v4/spreadsheets/" + comment_sheet_id + "/values/W16-A10!A2:K10000", + "https://sheets.googleapis.com/v4/spreadsheets/" + comment_sheet_id + "/values/F19!A2:K100000", true); + xhr.setRequestHeader('Authorization','Bearer ' + token); xhr.responseType = "json"; xhr.send(); + xhr.onload = function (oEvent) { + arrayBuffer = xhr.response; + console.log(arrayBuffer); + if(!arrayBuffer.values){ + last_row=1; + }else{ + last_row=arrayBuffer.values.length+1; + } + console.log("last row is " + last_row); + } + } else { @@ -51,9 +103,18 @@ function loadSpreadsheet() { }); } -function updateSheets(action, rubric_question, rubric_item, comment_info, comment) { - //console.log("updating sheets"); +function updateSheets(action, submission_num,rubric_question, rubric_item, comment_info, comment,tbox_num,assignment_name,grader_name,check_box_status,rubric_point,rubric_text) { + store_rubric_item=rubric_item; + console.log(typeof(store_rubric_item)); + console.log("store_rubric_item is "+store_rubric_item); + console.log("updating sheets now... for question "+rubric_question+"for item "+rubric_item); + console.log("comment_info is "+comment_info); // a comment was just inserted, update the google sheets to keep count & log this + + if(action=="onLeaving"){ + user_id=grader_name; + } + chrome.identity.getAuthToken({interactive: true}, function(token) { if (token) { console.log("got the token"); @@ -72,20 +133,20 @@ function updateSheets(action, rubric_question, rubric_item, comment_info, commen } }; - var row = parseInt(comment_info[0]) + 2; + var row = parseInt(comment_info[0]); var cur_frequency = parseInt(comment_info[8]); console.log("comment was from row " + row); console.log("frequency was " + cur_frequency); xhr.open("PUT", - "https://sheets.googleapis.com/v4/spreadsheets/" + comment_sheet_id + "/values/W16-A10!I" + row + "?valueInputOption=RAW", + "https://sheets.googleapis.com/v4/spreadsheets/" + comment_sheet_id + "/values/F19!I" + row + "?valueInputOption=RAW", true); xhr.setRequestHeader('Authorization','Bearer ' + token); xhr.setRequestHeader("Content-type", "application/json"); //xhr.responseType = "json"; xhr.send('{' + - '"range": "W16-A10!I' + row + '",' + + '"range": "F19!I' + row + '",' + '"values": [[' + (cur_frequency + 1) + ']]' + '}'); } @@ -94,7 +155,9 @@ function updateSheets(action, rubric_question, rubric_item, comment_info, commen // send event log to event log sheet chrome.storage.local.get(null, function(items) { - if (!items.user_id) { + + if (!items.user_id && user_id==undefined) { + console.log("undefied user id"); user_id = Math.random().toString(36) + new Date().getTime(); always_show = (Math.random() < 0.5); console.log("always show setting: " + always_show); @@ -113,6 +176,7 @@ function updateSheets(action, rubric_question, rubric_item, comment_info, commen if (rubric_item != undefined) { rubric_item = rubric_item.replace(/"/g, '\\"').replace(/'/g, "\\'"); + console.log("rubric_item after change: "+rubric_item); } var xhr2 = new XMLHttpRequest(); @@ -127,41 +191,69 @@ function updateSheets(action, rubric_question, rubric_item, comment_info, commen xhr2.open("POST", "https://sheets.googleapis.com/v4/spreadsheets/" + event_sheet_id + - "/values/A10!A2:H100000:append?valueInputOption=RAW", + "/values/A10!A2:H1000000:append?valueInputOption=RAW", true); xhr2.setRequestHeader('Authorization','Bearer ' + token); xhr2.setRequestHeader("Content-type", "application/json"); if (action == "comment") { xhr2.send('{' + - '"range": "A10!A2:H100000",' + + '"range": "A10!A2:H1000000",' + '"values": [[ "' + new Date().toString() + '", "comment", "' + comment_info[0] + '", "' + user_id + '", "' + - rubric_question + '", "' + rubric_item + '", "' + always_show + '", "' + comment + - '" ]]' + + rubric_question + '", "' + rubric_item + '", "' + always_show + '", "' + comment + '", "'+submission_num+ + '","" ]]' + '}'); } else if (action == "change setting") { xhr2.send('{' + - '"range": "A10!A2:H100000",' + + '"range": "A10!A2:H1000000",' + '"values": [[ "' + new Date().toString() + '", "change setting", "", "' + user_id + '", "", "", "' + always_show + - '", "" ]]' + + '", "","'+submission_num+'","" ]]' + '}'); } else if (action == "show suggestions" || action == "hide suggestions" || action == "focus") { xhr2.send('{' + - '"range": "A10!A2:H100000",' + + '"range": "A10!A2:H1000000",' + '"values": [[ "' + new Date().toString() + '", "' + action + '", "", "' + user_id + '", "' + - rubric_question + '", "' + rubric_item + '", "' + always_show + - '", "" ]]' + + rubric_question + '", "' + rubric_item + '", "' + always_show +'", "","'+submission_num+'","" ]]'+ '}'); } else if (action == "gradescope focus") { xhr2.send('{' + - '"range": "A10!A2:H100000",' + + '"range": "A10!A2:H1000000",' + + '"values": [[ "' + new Date().toString() + '", "' + action + '", "", "' + user_id + '", "' + + rubric_question + '", "", "' + always_show +'", "","'+submission_num+'","" ]]' + + '}'); + }else if (action == "pdf focus") { + xhr2.send('{' + + '"range": "A10!A2:H1000000",' + '"values": [[ "' + new Date().toString() + '", "' + action + '", "", "' + user_id + '", "' + - rubric_question + '", "", "' + always_show + - '", "" ]]' + + rubric_question + '", "", "' + always_show + '", "","'+submission_num+'","" ]]' + '}'); + }else if(action=="onLeaving"){ + console.log("ON LEAVINGGGGGG") + console.log(rubric_item) + xhr2.send('{' + + '"range": "A10!A2:H1000000",' + + '"values": [[ "' + new Date().toString() + '", "' + action + '", "", "' + user_id + '", "' + + rubric_question + '", "' + rubric_item + '", "' + always_show +'", "'+comment+'", "' +submission_num+ '", "'+tbox_num+'", "'+assignment_name+'", "' + +check_box_status+'", "' +grader_name+'", "'+rubric_point+'", "'+rubric_text+'","" ]]' + + '}'); } - }); + // if(action=="onLeaving"){ + // xhr2.open("POST", + // "https://sheets.googleapis.com/v4/spreadsheets/" + event_sheet_id + + // "/values/id_name!A2:H100000:append?valueInputOption=RAW", + // true); + // xhr2.setRequestHeader('Authorization','Bearer ' + token); + // xhr2.setRequestHeader("Content-type", "application/json"); + + // xhr2.send('{' + + // '"range": "id_name!A2:H100000",' + + // '"values": [[ "' + user_id + '", "' + grader_name+'","" ]]' + + // '}'); + // } + }); + + @@ -172,6 +264,8 @@ function updateSheets(action, rubric_question, rubric_item, comment_info, commen console.log("Not signed into Chrome, network error or no permission.\n" + message); } + + }); } @@ -207,6 +301,9 @@ function saveNewComment() { console.log(comments); var rubric_number = items.comments_rubric_number; var inserted_comments = items.comments_inserted; + var ass_num= items.assignment_num; + var sub_num= items.submission_num; + var rubric_item=items.rubric_item; console.log("inserted commentS:"); console.log(inserted_comments); @@ -241,7 +338,7 @@ function saveNewComment() { } if (already_there) continue; - var comment_length = comment.split(" ").length; + var comment_length = comment.length; // rubric question number (b) = items.rubric_number // if comment = one of the inserted comments, original id (e) = that inserted comment's id // then remove that comment from inserted comments @@ -250,23 +347,23 @@ function saveNewComment() { // category (h) = 0 // frequency (i) = 1 // frequency orig (j) = 1 - values += '[ "", "' + rubric_number + '", "", "", "", "' + - comment + '", "' + comment_length + '", "0", "1", "1", "", "' + user_id + '"' + + values += '[ "'+parseInt(last_row+1)+'", "' + rubric_number + '", "'+ ass_num+'", "'+rubric_item+'","'+sub_num+'", "' + + comment + '", "' + comment_length + '", "1", "1", "1", "", "' + user_id + '"' + ' ],' - + last_row++; } } // if any comments left in inserted comments, just append them and figure it out manually // be sure to include original comment id - for (var comment_id in inserted_comments) { - if (inserted_comments[comment_id] != "") { - values += '[ "", "' + rubric_number + '", "", "", "' + comment_id + '", "' + - inserted_comments[comment_id] + '", "' + inserted_comments[comment_id].split(" ").length + - '", "0", "1", "1", "", "' + user_id + '"' + - ' ],' - } - } + // for (var comment_id in inserted_comments) { + // if (inserted_comments[comment_id] != "") { + // values += '[ "", "' + rubric_number + '", "", "'+rubric_item+","+ comment_id + '", "' + + // inserted_comments[comment_id] + '", "' + inserted_comments[comment_id].length + + // '", "1", "1", "1", "", "' + user_id + '"' + + // ' ],' + // } + // } values = values.slice(0, values.length-1) + ']'; if (values != '"values": ]') { appendCommentsToSheet(values); @@ -298,18 +395,118 @@ function appendCommentsToSheet(values) { xhr.open("POST", "https://sheets.googleapis.com/v4/spreadsheets/" + comment_sheet_id + - "/values/W16-A10!A2:L10000:append?valueInputOption=RAW", + "/values/F19!A2:L100000:append?valueInputOption=RAW", true); xhr.setRequestHeader('Authorization','Bearer ' + token); xhr.setRequestHeader("Content-type", "application/json"); xhr.send('{' + - '"range": "W16-A10!A2:L10000",' + + '"range": "F19!A2:L100000",' + values + '}'); } }); } + + +function appendComments_pdf(pdf_list,rubric_question,rubric_item,submission_num,assignment_name,grader_name){ + console.log("do the append for the list from pdf"); + console.log(pdf_list); + var values='"values": ['; + for(var i=0;ispan +//note before start: refer to background.js for why there +//are comment[0,1,2,blabla] +//comment[0]==id(row number in google sheet) +//comment[1]==rubric question number +//comment[2]==assignment_number +//comment[3]==rubric_item +//comment[4]==submission_number +//comment[5]==comment text itself +//comment[6]==length of comment text(string) +//comment[8]==frequency +//comment[10]== if the comment is from PDF textbox +//comment[11]==user_id + + + var student_id; -var rubric_name; -var rubric_number; +var rubric_name;//question itself +var rubric_number; //the question itself var user_id; +var rubric_item_applied; var button_url; var full_comments; var always_show; @@ -11,18 +42,100 @@ var comment_text; // the text they have entered so far in the comment box var comments_inserted = {}; // list with text of comments they have inserted on this page. format: { id: text } // key = rubric question number, value = how many rubric items that question has // this is specific to A6 -var num_rubric_items = {1: 4, 2: 3, 3: 4, 4: 3, 5: 4, 6: 2, 7: 6}; + + +var being_clicked_in_pdf=new Set() +var already_on_pdf= new Set() +var Zdisabled=false +var window_url=window.location.href + +//console.log($('.taBox--textarea')); + + +// if(window.location.pathname.indexOf('assignments')>=0){ +// console.log("in batch page"); +// url_set= new Set(); +// var i=0; +// let list= $("a[class='link-noUnderline']"); +// while(i0){ + while(i<$('.taBox--textarea').length){ + var text=$('.taBox--textarea')[i].innerHTML + already_on_pdf.add(text) + + i++; + } +} +}); + +$(document).ready(function(){ + var student_name= $("abbr[role=button]").attr('aria-label'); + student_name=student_name.replace("and ",""); + + student_name_list= student_name.split(","); + for(var i=0;i 0) { - //console.log("rubric item " + ind); - storeAndPrintComments(comments[ind], this.id, ind); - //console.log("storing comments for rubric item " + ind); - //console.log(comments[ind]); - } else if (ind < num_rubric_items[rubric_number]) { - $("#search_" + this.id).hide(); + var rub=ind+1; + storeAndPrintComments(rub,comments[ind], ind, ind,false,false); + console.log("storing comments for rubric item " + ind); + console.log(comments[ind]); } + // else if (ind < num_rubric_items[rubric_number]) { + // $("#search_" + ind).hide(); + // } }); } @@ -83,27 +202,55 @@ function storeAndPrintAllComments(comments) { // id_num is the rubric item's HTML id (a long number) // index is its index in the list of rubric items // searching = true if this was called by the search function -function storeAndPrintComments(comments, id_num, index, searching) { +function storeAndPrintComments(rub,comments, id_num, index, searching,PDF) { + console.log("id num in store and print "+id_num); + id_num=id_num+1; + fit_comments=comments.filter(function(comment){ + return comment[3]==rub; + }); + comments=fit_comments; // specifies which rubric item suggestion box we are adding to + if(PDF){ + var selector_addition="#suggestion_box_pdf_"+id_num; + + }else{ var selector_addition = "#suggestion_box_" + id_num; - + } $(selector_addition + " .comments_good").html(""); - $(selector_addition + " .comments_bad").html(""); - $(selector_addition + " .comments_should").html(""); + // $(selector_addition + " .comments_bad").html(""); + // $(selector_addition + " .comments_should").html(""); + + //if comments is empty, just return + if(comments.length==0){ + return; + } + + + + + //sort the comments by the first word(move them together) + // comments= comments.sort(function(info1,info2){ + // var nameA= (info1[5].split(' '))[0].toLowerCase(); + // var nameB = (info2[5].split(' '))[0].toLowerCase(); + // if(nameA === nameB) return 0; + // return nameA > nameB ? 1 : -1; + + // }); + + // // sort comments ascending by length + // comments = comments.sort(function(info1, info2) { + // var length1 = parseInt(info1[6]); + // var length2 = parseInt(info2[6]); + // if (length1 < length2) { + // return -1; + // } else if (length1 == length2) { + // return 0; + // } else { + // return 1; + // } + // }); - // sort comments ascending by length - comments = comments.sort(function(info1, info2) { - var length1 = parseInt(info1[6]); - var length2 = parseInt(info2[6]); - if (length1 < length2) { - return -1; - } else if (length1 == length2) { - return 0; - } else { - return 1; - } - }); //console.log(comments); @@ -118,7 +265,22 @@ function storeAndPrintComments(comments, id_num, index, searching) { } else { return 1; } - }); + }); + + + comments = comments.sort(function(info1, info2) { + var length1 = parseInt(info1[6]); + var length2 = parseInt(info2[6]); + if (length1 < length2) { + return -1; + } else if (length1 == length2) { + return 0; + } else { + return 1; + } + }); + //PUT ONLY TOP 20 COMMENTS inside the box + //A10: put non-0 comments first (ones specific to this rubric question) var comments_0 = []; @@ -133,7 +295,7 @@ function storeAndPrintComments(comments, id_num, index, searching) { comments = comments_non0.concat(comments_0); - //console.log(comments); + console.log(comments); // get max and min frequency var max_freq = parseInt(comments[0][8]); var min_freq = parseInt(comments[0][8]); @@ -166,19 +328,33 @@ function storeAndPrintComments(comments, id_num, index, searching) { blank_values = comments[i][10].split(", "); } + //NOTE: Upon Mia's request, the shade is no longer implemented here because sorting is already + //done, but always feel free to add shade back + //just change the rgb value from 0 to shade + if(!PDF){ var string = "" + - "" + - "" + comment + "" + + " class='comment' style='color: rgb(" + 0 + ", " + 0 + ", " + 0 + ")'>" + + "" + + "" + comment + "" + ""; - + }else{ + var string = "" + + "" + + "" + comment + "" + + ""; + } if (category == "1") { - $(selector_addition + " .comments_good").append(string); - } else if (category == "2") { - $(selector_addition + " .comments_bad").append(string); - } else if (category == "3") { - $(selector_addition + " .comments_should").append(string); - } else { + $(selector_addition + " .comments_good").append(string); + // var tdd="."+"tdd_"+i + + // if($(tdd).children().length==1 && !PDF){ + + // var resultLink=makeTdWithLink(comment,blank_values,i) + // console.log(resultLink) + // $(tdd).parents('tr').append(resultLink) + // } + }else { $(selector_addition + " .comments_should").append("error with comment category"); } @@ -187,7 +363,7 @@ function storeAndPrintComments(comments, id_num, index, searching) { $(selector_addition).find(".comment_" + i).each(function() { - var blanks = $(this).attr("data-blanks").split(","); + var blanks = $(this).attr("datablanks").split(","); $(this).find(".blank").each(function() { $(this).attr("placeholder", blanks[$(this).index()]); @@ -196,28 +372,88 @@ function storeAndPrintComments(comments, id_num, index, searching) { } } - + + + if (!searching) { // save these for the button callback's use - full_sorted_comments[index] = comments; + full_sorted_comments[index] = comments; // hide search bar if there are 5 or less comments (unnecessary) - if (comments.length <= 6) { + if (comments.length <= 5) { $("#search_" + id_num).hide(); } } - + + + + //add the comment to the ta-box when the btn_pdf is clicked + $('.btn_pdf').on('click',function(){ + + var btn_id_num = $(this).attr("class").split(" ")[1]; + var this_index = $(this).parents("div").attr('id').slice(-1)-1; + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + //var comment= $(this).parents("tr").find(".comment_"+btn_id_num).text(); + var comment = full_sorted_comments[this_index][btn_id_num][5]; + var $temp = $(""); + $("body").append($temp); + $temp.val($(this).parents("tr").find(".comment_"+btn_id_num).text()).select(); + document.execCommand("copy"); + $temp.remove(); + console.log("inserting comment: " + comment); + console.log(full_sorted_comments[this_index]); + console.log(full_sorted_comments[this_index][btn_id_num]); + var comment_id = full_sorted_comments[this_index][btn_id_num][0]; + insertComment_pdf(comment,comment_id); + being_clicked_in_pdf.add(comment); + chrome.runtime.sendMessage({action: "logEvent", + comment_info: full_sorted_comments[this_index][btn_id_num], + rubric_question: rubric_name, + rubric_item: rubric_item, + comment: comment, + submission_num: sub_number + }, function(response) { + console.log(response); + }); +}); + + + + + + + // // simulate blur so the new comment will save + // var event = new KeyboardEvent('keydown'); + // document.querySelector('.taBox--textarea').dispatchEvent(event); + + // }); + + + + + // make insert buttons clickable $(".btn").unbind("click"); $(".btn").click(function(obj) { - // button clicked! insert suggestion + // button clicked! insert suggestion var btn_id_num = $(this).attr("class").split(" ")[1]; - // index of this rubric item = index of these comments in full_sorted_comments - var this_index = $(this).parents("li.rubric-item").index(); - //console.log(this_index); - - var comment = $(this).parents("tr").find(".comment_" + btn_id_num).html(); + // index of this rubric item = index of these comments in full_sorted_comments + //* find the gradescope correspondence here*** + var this_index = $(this).parents("div").attr('id').slice(-1)-1; + console.log(this_index); + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + var rubric_item=$(".rubricItem--key-applied").html(); + rubric_item_applied=rubric_item; + console.log("inserting comment: " + comment); + console.log(full_sorted_comments[this_index]); + console.log(full_sorted_comments[this_index][btn_id_num]); + var comment_id = full_sorted_comments[this_index][btn_id_num][0]; + + //var comment = $(this).parents("tr").find(".comment_" + btn_id_num).html(); + var comment = full_sorted_comments[this_index][btn_id_num][5]; //console.log(comment); // remove the blanky stuff @@ -231,38 +467,78 @@ function storeAndPrintComments(comments, id_num, index, searching) { comment = comment.replace(/"/g, '\\"').replace(/'/g, "\\'"); - var rubric_item = $(this).parents("li.rubric-item").find(".rubric-description").find(".mathInput--preview").html(); - - console.log("inserting comment: " + comment); - console.log(full_sorted_comments[this_index]); - console.log(full_sorted_comments[this_index][btn_id_num]); - var comment_id = full_sorted_comments[this_index][btn_id_num][0]; + //var rubric_item = $(this).parents("li").find(".rubricItem--pointsAndDescription").find(".rubricField-points").html(); insertComment(comment, comment_id); chrome.runtime.sendMessage({action: "logEvent", comment_info: full_sorted_comments[this_index][btn_id_num], rubric_question: rubric_name, - rubric_item: rubric_item, - comment: comment + rubric_item: rubric_item, + comment: comment, + submission_num: sub_number }, function(response) { - console.log(response); + console.log(response); }); }); } +$(".rubricItem--key").change(function(){ + + var rubric_item_score=$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(); + try{ + var arr=$(".submissionGraderPoints").html().split(" ") + } + catch(error){ + return + } + arr.pop() + var total_score=arr.pop() + var res_total="+"+total_score + if(rubric_item_score==undefined && $(".taBox--displayText").length==0 && $(".form--textArea").val()=="" ){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true); + return + } + if(rubric_item_score !=="-0.0"){ + if(rubric_item_score.substring(0,1)!="-"){ + if(rubric_item_score==res_total){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + if($('.tabox--textarea').length>0){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true); + } + }else{ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + }) + + + function updateCommentViews(view_id) { + + console.log('view_id is '+view_id); setTimeout(function(){ $(".comment_view_text").each(function(ind) { if (view_id == undefined || this.id != view_id) { - $(this).val($("#question_submission_evaluation_comments").val()); + $(this).val($(".form--textArea").val()); } }); // save current text - comment_text = $('#question_submission_evaluation_comments').val(); + comment_text = $('.form--textArea').val(); if (original_text != "") { var split = comment_text.split(original_text); + console.log("split is: "+split); if (split.length == 2) { comment_text = split[1]; } else { @@ -271,23 +547,35 @@ function updateCommentViews(view_id) { } console.log("got updated comments: ") console.log(comment_text); + if(comment_text!==""){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + }else if(comment_text=="" && $('.taBox--textarea').length==0){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true) + + }else{ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + } chrome.storage.local.set({comment_text: comment_text, comments_inserted: comments_inserted, - comments_rubric_number: rubric_number, saved: false}); + comments_rubric_number: rubric_number, saved: false,rubric_item:rubric_item_applied}); }, 100); } function updateCommentBox(view_id) { + console.log("In update, this.id is "+view_id); setTimeout(function(){ - $("#question_submission_evaluation_comments").val($("#" + view_id).val()); + $(".form--textArea").val($("#" + view_id).val()); setTimeout(function() { updateCommentViews(view_id); }, 1000); }, 100); // simulate blur so the new comment will save var event = new KeyboardEvent('blur'); - document.querySelector('#question_submission_evaluation_comments').dispatchEvent(event); + document.querySelector('.form--textArea').dispatchEvent(event); } // comment has been clicked. Add it to the gradescope comment box. @@ -296,23 +584,32 @@ function insertComment(comment, comment_id) { comment = comment.replace(/\\"/g, '"').replace(/\\'/g, "'"); comments_inserted[comment_id] = comment; - - $("#question_submission_evaluation_comments").val( - $("#question_submission_evaluation_comments").val() + "\n" + comment + "\n"); - $("#question_submission_evaluation_comments").height($("#question_submission_evaluation_comments")[0].scrollHeight); - //console.log("doin it"); + //find if the corresponding gradescope name changed + $(".form--textArea").val( + $(".form--textArea").val() + "\n" + comment + "\n"); + $(".form--textArea").height($(".form--textArea")[0].scrollHeight); + //console.log("making the insertion"); // simulate blur so the new comment will save var event = new KeyboardEvent('keydown'); - document.querySelector('#question_submission_evaluation_comments').dispatchEvent(event); + document.querySelector('.form--textArea').dispatchEvent(event); +} + + +function insertComment_pdf(comment,comment_id){ + comment = comment.replace(/\\"/g, '"').replace(/\\'/g, "'"); + comments_inserted[comment_id] = comment; } + function searchComments(query, search_id) { var id_num = search_id.split("search_")[1]; - var result_comments = []; + //TODO:change box index, I think it should be 0 if we display all the comments? var box_index = $("#" + id_num).index(); - var comments_to_search = full_comments[box_index]; + console.log("box index: "+box_index); + console.log("full comments has a thing: "+full_comments[full_comments.length-1]); + var comments_to_search = full_comments[full_comments.length-1]; for (var i = 0; i < comments_to_search.length; i++) { var comment = comments_to_search[i]; @@ -322,7 +619,7 @@ function searchComments(query, search_id) { } console.log("calling store and print from search"); console.log(result_comments); - storeAndPrintComments(result_comments, id_num, $("#" + id_num).index(), true); + storeAndPrintComments(id_num,result_comments, id_num-1, id_num-1, true); } function toggleSuggestionBox(id_num) { @@ -363,61 +660,374 @@ function injectSuggestions() { display_setting = ""; } + //TODO: now gradescope has no id for the li.rubricEntryDragContainer $("li.rubricEntryDragContainer").each(function(ind) { - + var this_id=$(this).find(".rubricItem--key").html(); + // don't show suggs for None rubric item if (ind < num_rubric_items[rubric_number]) { - + + //var this_id=$(this).find(".rubricItem--key").html(); + //console.log("new var value is "+this_id); $(this).append( - "
" + + "
" + "" + toggle_word + " suggestions..." + "
" + - "
" + - "
" + - "" + - '
"I wish..."
' + - "
" + - '
"I suggest..."
' + - "
" + - '
"I like..."
' + + "
" + + "
" + + "" + + '
Suggestions:
' + "
" + "
" + - '
' + - '' + - '
' + "
" ); - $(this).find(".comment_view_text").val($("#question_submission_evaluation_comments").val()); + //$(this).find(".comment_view_text").val($(".form--textarea").val()); } }); - // event listener to update everything when comment view text is changed - $(".comment_view_text").keydown(function() { updateCommentBox(this.id); }); - $(".comment_view_text").focus(function() { - var rubric_item = $(this).parents("li.rubric-item").find(".rubric-description").find(".mathInput--preview").html(); - // tell chrome to log the event that we just clicked the comment box - chrome.runtime.sendMessage({action: "logFocus", - rubric_question: rubric_name, - rubric_item: rubric_item - }, function(response) { - console.log("logging focus: " + response); - }); +$( +"
"+ +"

Comments you put directly on the PDF:

"+ +"
" + +).insertAfter(".form--textArea") + +$(document).ready(function(){ + b=Array.from(already_on_pdf) + console.log(b.length) + for(var i=0;i"+b[i]+""+"
") + } +}); + + + + + + $( + "
"+ + "Your feedback should be specific, actionable, and justified. Check the boxes below if your comments meet the criteria. You can press 'z' for the next question as long as you write a comment if the student did not receive full credit."+ + "
"+ + "Is specific"+ + "Is actionable"+ + "Is justified"+ + "
" + ).insertAfter(".pdf_comments_display"); + + + + + + // //disable the nextQuestion button until all checkbox clicked + // $(document).ready(function(){ + + // let cur_url= window.location.href + // chrome.storage.local.get(null, function(items){ + // url_list= items.url_list; + // console.log(url_list.length); + // url_list.forEach(function(element){ + // if(cur_url.indexOf(element)>-1){ + // url_list=url_list.filter(function(a){return a!==element;}); + // } + // }); + // console.log(url_list.length); + // chrome.storage.local.set({url_list:url_list}); + // if((url_list).length>0){ + // console.log($(".actionBar--action-next")[0].href); + // $(".actionBar--action-next")[0].href=url_list[Math.floor(Math.random() * url_list.length)]; + // console.log($(".actionBar--action-next")[0].href); + // } + // }) + // }); + + + //trigger word function(bonus point): some words can trigger checkboxes to be cliked + $('.form--textArea').change(function(){ + comment_text = $('.form--textArea').val(); + comment_split=comment_text.split(" "); + if (comment_split.includes('may')||comment_split.includes('should')){ + $('.catCheck--act').prop('checked',true); + } + if(comment_split.includes('because')||comment_split.includes('so')){ + $('.catCheck--just').prop('checked',true); + } + }); + $(document).change(function(){ + if($('input[class="catCheck--spec"]').is(':checked')){ + if($('input[class="catCheck--act"]').is(':checked')){ + if($('input[class="catCheck--just"]').is(':checked')){ + $('#ins_check').text('Good to go!'); + $('#ins_check').css('color','green'); + + }else{ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a justification for your comment'); + } + }else if($('input[class="catCheck--just"]').is(':checked')){ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a concrete suggestion to your comment to make it actionable'); + }else{ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a concrete suggestion to your comment to make it actionable'); + } + }else if($('input[class="catCheck--act"]').is(':checked')){ + if($('input[class="catCheck--just"]').is(':checked')){ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a concrete suggestion to your comment to make it actionable'); + }else{ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a concrete suggestion to your comment to make it actionable'); + } + }else if($('input[class="catCheck--just"]').is(':checked')){ + $('#ins_check').css('color','red'); + $('#ins_check').text('Please add a concrete suggestion to your comment to make it actionable'); + }else{ + $('#ins_check').css('color','red'); + $('#ins_check').text('If you believe your comment meets the criteria listed below, check them.'); + } + + + }); + + + + + + //hide all the suggestion first, then let the related suggestions pop up as needed + $(document).ready(function(){ + if(!always_show){ + hideAllSuggestions(); + id_already_there=$('.rubricItem--key-applied').html(); + if (!$('suggestion_container_'+id_already_there).is(":visible")) { + toggleSuggestionBox(id_already_there); + } + } + }); + + + $(document).ready(function(){ + $('.btnGroup--btn-flex').append("(page will refresh after add item)"); + }); + + + + + +$(document).ready(function(){ + if(rubric_item_score==undefined && $(".form--textArea").val()=="" && $('.taBox--displayText').length==0){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true); + return + } +var rubric_item_score=$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(); +try{ + var arr=$(".submissionGraderPoints").html().split(" ") + } + catch(error){ + return + } +//var arr=$(".submissionGraderPoints").html().split(" ") +arr.pop() +var total_score=arr.pop() +var res_total="+"+total_score +console.log(rubric_item_score) +console.log(total_score) +console.log(res_total) +if(rubric_item_score !=="-0.0"){ + try{ + if(rubric_item_score.substring(0,1)!="-"){ + if(rubric_item_score==res_total){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + } +} +catch(error){ + return +} + var text=$('.form--textArea').val() + console.log(text) + if(text=="" ||$('.taBox--textarea').length==0){ + console.log("START TRUE") + Zdisabled=true + + }else{ + Zdisabled=false + } +} +if(Zdisabled){ + $(".actionBar--action-next").attr('disabled',true); + }else{ + $(".actionBar--action-next").attr('disabled',false); + } + +}); + + + + //Things in here is to make the selection of rubric items can be both be clicked/by keyboard +// Select the node that will be observed for mutations +const targetNode = document.getElementsByClassName('rubricItem--key'); +console.log(targetNode); + +// Options for the observer (which mutations to observe) +const config = { attributes: true, childList: true, subtree: true }; + + +const callback = function(mutationsList, observer) { + for(let mutation of mutationsList) { + if (mutation.type === 'childList') { + console.log('A child node has been added or removed.'); + } + else if (mutation.type === 'attributes') { + var classList = mutation.target.className; + console.log(classList) + console.log(mutation.target) + if(classList.indexOf("rubricItem--key-applied")>=0){ + // let len_rb=$(".rubricItem--key-applied").length-1 + // let item_rb=$(".rubricItem--key-applied")[len_rb] + // console.log(item_rb) + rubric_item=mutation.target.innerHTML + console.log(rubric_item) + $('.pageViewerControls.u-pointerEventsNone').append($( + "
" + + "
PDF SUGGESTION BOX:DRAG PDF TO ME!
"+ + "
" + + '
"Suggestions: Clicking the button by the suggested comment will copy it. Simply paste it in your comment box after"
' + + "
" + + "
" + + "
" + )); + + var rubric_item_score=$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(); + var arr=$(".submissionGraderPoints").html().split(" ") + arr.pop() + var total_score=arr.pop() + var res_total="+"+total_score + if(rubric_item_score !=="-0.0"){ + + if($('.form--textArea').val()!=="" || $(".taBox--displayText").length>0){ + + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + } + else if(rubric_item_score.substring(0,1)!="-"){ + if(rubric_item_score==res_total){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + + } + }else{ + + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true); + } + }else{ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + + } + if(rubric_item_score==undefined){ + if($(".form--textArea").val()!==""|| $(".taBox--textarea").length>0){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + } + } + + //$("
NAIVEEEEEE
").insertAfter('.taBox--textarea'); + try{ + storeAndPrintComments(rubric_item,full_sorted_comments[rubric_item-1], rubric_item-1, rubric_item-1, false,true); + } + catch(error){ + console.log(error) + } + + if(!always_show){ + var id=mutation.target.innerHTML; + console.log("IIID is: "+id); + if (!$('suggestion_container_'+id).is(":visible")) { + toggleSuggestionBox(id); + } + } + }else{ + $('.suggestion_container_pdf').remove(); + if($(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html()==undefined){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true); + } + var id=$(mutation.target).html(); + console.log("IIID dis appear is: "+id); + if (!$('suggestion_container_'+id).is(":visible") && !always_show) { + toggleSuggestionBox(id); + } + } + + } + } +}; + +// Create an observer instance linked to the callback function +const observer = new MutationObserver(callback); + +// // Start observing the target node for configured mutations +for(var i=0;i span > span").html(); - + //console.log("RRRRRDD "+rubric_item); //TODO: get student id student_id = "temp"; rubric_number = rubric_name.split(":")[0]; //console.log("rubric number: " + rubric_number); var rubric_name_lower = rubric_name.toLowerCase(); + + //Add a new rubric item, then it should refresh on thei + $(document).on('DOMNodeInserted', function(e) { + //console.log("should REFRESH!"); + //console.log(e.target); + if ( $(e.target).hasClass('rubricEntryDragContainer') ) { + //element with rubricItem was inserted, refresh the page + //alert("Sorry dude, the page needs to be reloaded to update rubric items, click 'OK' to continue"); + window.location.reload(); + } + }); + + $(document).ready(function(){ + $("rubricItem--key").click(function(){ + $(".suggestion_container").css('display','block'); + }); + + }); // change true so that it only works on grading pages - if (true) { + if (window.location.pathname.indexOf('grade')>=0 && window.location.pathname.indexOf('assignments')==-1) { // tell chrome we are on a grading page chrome.runtime.sendMessage({action: "onGradingPage"}); button_url = chrome.extension.getURL("button.png"); - + rubric_item_applied=$('.rubricItem--key-applied').html(); // get text currently in comment box - original_text = $("#question_submission_evaluation_comments").val(); + //original_text = $(".form--textArea").val(); console.log("original text:"); console.log(original_text); // event listener for whenever comment box updates, to update all the comment views too - $("#question_submission_evaluation_comments").keydown(function() { - updateCommentViews(); - }); - - $("#question_submission_evaluation_comments").focus(function() { - // tell chrome to log the event that we just clicked the comment box - chrome.runtime.sendMessage({action: "logGradescopeFocus", - rubric_question: rubric_name, - }, function(response) { - console.log("logging gradescope focus: " + response); - }); - }); + $(".form--textArea").keydown(function() { + setTimeout(function(){ + + // save current text, so that the thing will be stored, and this works + comment_text = $('.form--textArea').val(); + if (original_text != "") { + var split = comment_text.split(original_text); + console.log("comment split AAA: "+split); + if (split.length == 2) { + comment_text = split[1]; + } else { + comment_text = split[0]; + } + } + console.log("got updated comments: ") + console.log(comment_text); + if(comment_text!==""){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + }else if(comment_text=="" && $('.taBox--textarea').length==0){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true) + + }else{ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + } + + chrome.storage.local.set({comment_text: comment_text, comments_inserted: comments_inserted, + comments_rubric_number: rubric_number, saved: false,rubric_item:rubric_item_applied}); + }, 100); + + }); + + // $(".form--textArea").focus(function() { + // // tell chrome to log the event that we just clicked the comment box + // chrome.runtime.sendMessage({action: "logGradescopeFocus", + // rubric_question: rubric_name, + // submission_num:sub_number + // }, function(response) { + // console.log("logging gradescope focus: " + response); + // }); + // }); // wait to receive the comments from spreadsheet chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - //console.log("got comments message"); + console.log("got comments message"); if (request.comments) { console.log("storing and printing comments"); + //TODO: made the comments customized for each question(rubric_number) full_comments = filterComments(request.comments); //console.log(full_comments); storeAndPrintAllComments(full_comments); @@ -501,12 +1181,16 @@ $(function() { chrome.storage.local.set({student_id: student_id, rubric_number: rubric_number}, function() { console.log("Saved page info"); + chrome.storage.local.get(function(result){console.log(result)}) + + }); // get user id and settings chrome.storage.local.get(null, function(items) { if (!items.user_id) { - user_id = Math.random().toString(36) + new Date().getTime(); + user_id = grader_name + // Math.random().toString(36) + new Date().getTime(); always_show = (Math.random() < 0.5); console.log("always show setting: " + always_show); chrome.storage.local.set({user_id: user_id, always_show: always_show}); @@ -524,9 +1208,384 @@ $(function() { injectSuggestions(); }); - } else { - // tell chrome we are NOT on a grading page - chrome.runtime.sendMessage({action: "onOtherPage"}); } + + + $('.actionBar--action-next').click(everyUnloading); + +// $(window).on('beforeunload', everyUnloading + +// // console.log("LEAVING"); +// // console.log("SEND PDF COMMENTS"); + +// // //console.log($('.taBox--textarea')[0].innerHTML); +// // var i=0; +// // if($('.taBox--textarea').length>0){ +// // var pdf_text_list=[] +// // while(i<$('.taBox--textarea').length){ +// // var text=$('.taBox--textarea')[i].innerHTML +// // if(!being_clicked_in_pdf.has(text) && !already_on_pdf.has(text)){ +// // text=checkEqualTextPDF(text,full_sorted_comments) +// // if(text!==undefined){ +// // pdf_text_list.push(text) +// // } +// // } +// // i++; +// // } + +// // being_clicked_in_pdf.clear(); +// // console.log(pdf_text_list) +// // if(pdf_text_list.length>0){ +// // chrome.runtime.sendMessage({action:"sendPDFbox", +// // pdf_list: pdf_text_list, +// // rubric_question:rubric_number, +// // rubric_item:$(".rubricItem--key-applied").html(), +// // submission_num:sub_number, +// // assignment_name: ass_number, +// // grader_name:user_id + +// // },function(response) { +// // console.log("logging focus: " + response); +// // //console.log("RRRRRRRRR "+rubric_item); +// // }); +// // } + +// // } +// // console.log(":LOAD EVERYTHING") +// // if($('input[name="category"]:checked').length==0){ +// // var checked=""; +// // } +// // else{ +// // temp=[] +// // for(var i=0;i<$('input[name="category"]:checked').length;i++){ +// // var name=$('input[name="category"]:checked')[i].value +// // temp.push(name) +// // } +// // checked=temp.join(); +// // } +// // chrome.runtime.sendMessage({action: "onLeaving", +// // tbox_num:$('.taBox--textarea').length, +// // rubric_question:rubric_name, +// // rubric_item: $(".rubricItem--key-applied").html(), +// // rubric_point:$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(), +// // rubric_text: $(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children(".rubricField-description").html(), +// // comment: $('.form--textArea').val(), +// // submission_num:sub_number, +// // assignment_name: ass_name, +// // grader_name:grader_name, +// // check_box_status:checked +// // }); +// ); + // else { + // // tell chrome we are NOT on a grading page + // chrome.runtime.sendMessage({action: "onOtherPage"}); + // } }); + + +function everyUnloading(){ + + console.log("LEAVING"); + console.log("SEND PDF COMMENTS"); + + //console.log($('.taBox--textarea')[0].innerHTML); + var i=0; + if($('.taBox--textarea').length>0){ + var pdf_text_list=[] + while(i<$('.taBox--textarea').length){ + var text=$('.taBox--textarea')[i].innerHTML + if(!being_clicked_in_pdf.has(text) && !already_on_pdf.has(text)){ + text=checkEqualTextPDF(text,full_sorted_comments) + if(text!==undefined){ + pdf_text_list.push(text) + } + } + i++; + } + + being_clicked_in_pdf.clear(); + already_on_pdf.clear(); + console.log(pdf_text_list) + if(pdf_text_list.length>0){ + chrome.runtime.sendMessage({action:"sendPDFbox", + pdf_list: pdf_text_list, + rubric_question:rubric_number, + rubric_item:$(".rubricItem--key-applied").html(), + submission_num:sub_number, + assignment_name: ass_number, + grader_name:grader_name + + },function(response) { + console.log("logging focus: " + response); + //console.log("RRRRRRRRR "+rubric_item); + }); + } + + } + console.log(":LOAD EVERYTHING") + if($('input[name="category"]:checked').length==0){ + var checked=""; + } + else{ + temp=[] + for(var i=0;i<$('input[name="category"]:checked').length;i++){ + var name=$('input[name="category"]:checked')[i].value + temp.push(name) + } + checked=temp.join(); +} + chrome.runtime.sendMessage({action: "onLeaving", +tbox_num:$('.taBox--textarea').length, +rubric_question:rubric_name, +rubric_item: $(".rubricItem--key-applied").html(), +rubric_point:$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(), +rubric_text: $(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children(".rubricField-description").html(), +comment: $('.form--textArea').val(), +submission_num:sub_number, +assignment_name: ass_name, +grader_name:grader_name, +check_box_status:checked +}); +} + + + + +function shortenComment(comment){ + //Find the string length + if(comment.length>=100){ + return comment.substring(0,100); + } + return comment; + } + + +function makeTdWithLink(comment,blank_values,i){ + var len=100 + var row=document.createElement("td") + row.class="comment_"+i; + row.datablanks=blank_values + var link=document.createElement("a") + row.innerHTML = comment.substring(0,len); + link.innerHTML=comment.length>len?".....":"" + link.href="javascript:void(0)"; + link.onclick=function(){ + if(link.innerHTML.indexOf("...")>0){ + }else{ + link.innerHTML="HIDE" + row.innerHTML=comment + } + } + row.appendChild(link) + return row +} + + + +function makeCommentLink(comment){ + var len=100; + var row=document.createElement("span") + var link=document.createElement("a") + link.innerHTML=comment.length>len?".....":""; + link.href="javascript:void(0)"; + link.onclick=function(){ + if(link.innerHTML.indexOf("...")>=0){ + row.innerHTML=comment(len,comment.length) + }else{ + link.innerHTML="HIDE" + } + } + row.appendChild(link) + return row +} + + + +$('.form--textArea').change(function(){ + var rubric_item_score=$(".rubricItem--key-applied").siblings(".rubricItem--pointsAndDescription").children("button").html(); + +if(rubric_item_score==undefined){ + + let text1=$('.form--textArea').val() + if(text1!==""){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + } + +try{ +var arr=$(".submissionGraderPoints").html().split(" ") +} +catch(error){ + return +} +arr.pop() +var total_score=arr.pop() +var res_total="+"+total_score + +if(rubric_item_score !=="-0.0"){ + if(rubric_item_score.substring(0,1)!="-"){ + if(rubric_item_score==res_total){ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false); + return + } + } + var text=$('.form--textArea').val() + console.log(text) + if(text=="" && $('.taBox--textarea').length==0){ + Zdisabled=true + }else{ + Zdisabled=false + } +}else{ + Zdisabled=false +} +if(Zdisabled){ + $(".actionBar--action-next").attr('disabled',true); + }else{ + $(".actionBar--action-next").attr('disabled',false); + } + +}); + + +// check if the current comments is +function checkEqualTextPDF(comment,full_comments){ + for(let i=0;i=0){ + //only accept addendum to original comments + if(comment.indexOf(full_comments[full_comments.length-1][i][5])==0){ + return comment.substring(comment.indexOf(full_comments[full_comments.length-1][i][5])+full_comments[full_comments.length-1][i][5].length); + } + }else{ + continue + } + } + return comment +} + + + +document.addEventListener('keydown',switchZ,true); +function switchZ(event){ + var keycode=event.key; + if(keycode=='z' &&Zdisabled){ + + event.stopImmediatePropagation(); +}else if(keycode=='z' &&!Zdisabled){ + if(!$('.form--textArea').is(':focus') && !$('taBox--textarea').is(':focus')){ + var text=$('.form--textArea').val() + everyUnloading() + + } + // $(document).unbind(); + // $(document).bind() + //document.removeEventListener('keydown',switchZ,true); + //alert("FUCK") + //everyUnloading() + +// } +} +} + + + + +$(document).change(function(){ + + var everything_on_pdf=new Set() + console.log(Array.from(everything_on_pdf).length) + + for(var i=0;i<$('.taBox--textarea').length;i++){ + var text=$('.taBox--textarea')[i].innerHTML + if(text!==""){ + everything_on_pdf.add(text) + } + } + console.log(Array.from(everything_on_pdf).length) + if(Array.from(everything_on_pdf).length==0 && $(".form--textArea").val().length==0){ + Zdisabled=true + $(".actionBar--action-next").attr('disabled',true) + }else{ + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + } + //more comments on the pdf not on the right + if($('.anchor_on_right').length<$('.taBox--textarea').length){ + console.log($('.anchor_on_right').length) + var set_on_right=new Set() + for(var j=0;j<$('.anchor_on_right').length;j++){ + var right_text=$('.anchor_on_right')[j].innerHTML + set_on_right.add(right_text) + } + let diff=new Set([...everything_on_pdf].filter(x => !set_on_right.has(x))); + var text=Array.from(diff)[0] + console.log(text) + $('.pdf_comments_display').append(""+text+""+"
") + + // var text=$('.anchor_on_right')[j].innnerHTML; + // if(!everything_on_pdf.has(text)){ + // $('.pdf_comments_display').append(""+text+""+"
") + // } + + }else if($('.anchor_on_right').length>Array.from(everything_on_pdf).length){ + for(var k=0;k<$('.anchor_on_right').length;k++){ + var new_right_text=$('.anchor_on_right')[k].innerHTML + if(!everything_on_pdf.has(new_right_text)){ + $('.anchor_on_right')[k].innerHTML=""; + $('.anchor_on_right')[k].remove() + } + } + }else if($('.anchor_on_right').length==Array.from(everything_on_pdf).length){ + var set_on_right=new Set() + for(var j=0;j<$('.anchor_on_right').length;j++){ + var right_text=$('.anchor_on_right')[j].innerHTML + set_on_right.add(right_text) + } + let diff_e_to_r=new Set([...everything_on_pdf].filter(x => !set_on_right.has(x))); + + if(diff_e_to_r.size!=0){ + let diff_r_to_e=new Set([...set_on_right].filter(x => !everything_on_pdf.has(x))); + + let text_to_update=Array.from(diff_r_to_e)[0] + let text_from_pdf=Array.from(diff_e_to_r)[0] + console.log(text_from_pdf) + for(var k=0;k<$('.anchor_on_right').length;k++){ + var text=$('.anchor_on_right')[k].innerHTML + if(text==text_to_update){ + $('.anchor_on_right')[k].innerHTML=text_from_pdf + } + } + + } + + } +}) + + +// $(document).change(function(){ + +// if($('.taBox--displayText').length>0 ||$(".form--textArea").val()!==""){ +// alert("FUCK") +// Zdisabled=false +// $(".actionBar--action-next").attr('disabled',false) +// } + +// }); + + +$(document).ready(function(){ + if($('.taBox--displayText').length>0){ + + Zdisabled=false + $(".actionBar--action-next").attr('disabled',false) + } +}); + + + diff --git a/dialog.png b/dialog.png new file mode 100644 index 0000000..c0a5074 Binary files /dev/null and b/dialog.png differ diff --git a/manifest.json b/manifest.json index ae76793..19dfb05 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Feedback Prototype", "description": "Suggests previous gradescope comments for feedback", - "version": "8.3", + "version": "8.5.1", "browser_action": { "default_popup": "popup.html" @@ -20,6 +20,7 @@ }, "permissions": [ + "tabs", "activeTab", "storage", "identity", @@ -28,9 +29,15 @@ "content_scripts": [ { "matches": ["https://gradescope.com/*/questions/*/submissions/*/grade", - "https://www.gradescope.com/courses/*/questions/*/submissions/*/grade"], + "https://www.gradescope.com/courses/*/questions/*/submissions/*/grade","https://www.gradescope.com/courses/*/questions/*/submissions/*/grade?not_grouped=true", + "https://www.gradescope.com/courses/*/assignments/*/grade"], "js": ["jquery-2.2.2.min.js", "content_script.js"], "css": ["suggestions.css"] + }, + { + "matches": ["https://www.gradescope.com/courses/*/assignments/*/submissions/*"], + "js": ["jquery-2.2.2.min.js","student_content_script.js"], + "css": ["student_view.css"] } ], "background": { @@ -38,11 +45,11 @@ "persistent": false }, "oauth2": { - "client_id": "429303545529-bag73oigjvq64981cd2f0rvvqbbekbqe.apps.googleusercontent.com", // debug - //"client_id": "429303545529-hq5ehbbgd6quoa2qneg2q3icqfjj50kg.apps.googleusercontent.com", //published + "client_id":"66462531215-1prsgpfbnfl2mf88e27165g1vcv70pjl.apps.googleusercontent.com", "scopes": [ "https://spreadsheets.google.com/feeds" ] }, - "web_accessible_resources": ["button.png"] + "web_accessible_resources": ["button.png","dialog.png"] + } \ No newline at end of file diff --git a/popup.js b/popup.js index bd8ace0..0890171 100644 --- a/popup.js +++ b/popup.js @@ -55,14 +55,15 @@ document.addEventListener('DOMContentLoaded', function() { chrome.storage.local.get(null, function(items) { if (!items.user_id) { user_id = Math.random().toString(36) + new Date().getTime(); - always_show = (Math.random() < 0.5); + always_show=false; + // always_show = (Math.random() < 0.5); console.log("always show: " + always_show); chrome.storage.local.set({user_id: user_id, always_show: always_show}); } else if (items.always_show == undefined) { user_id = items.user_id; - always_show = (Math.random() < 0.5); + always_show = false; console.log("always show: " + always_show); - chrome.storage.local.set({always_show: always_show}); + chrome.storage.local.set({always_show: false}); } else { user_id = items.user_id; always_show = items.always_show; diff --git a/student_content_script.js b/student_content_script.js new file mode 100644 index 0000000..7d529b0 --- /dev/null +++ b/student_content_script.js @@ -0,0 +1,48 @@ + +//this is the js file for adding the sbadge for student view in gradescope +var dialog_url; +dialog_url = chrome.extension.getURL("dialog.png"); +//var htmlobj= $("div[data-react-class]")[0].outerHTML; +var attrobj= jQuery.parseJSON($("div[data-react-class]").attr('data-react-props')); +console.log(attrobj); +var q_dict={} +var attrArray = attrobj['inorder_leaf_question_ids'] + +//console.log(typeof(attrArray[0])) +//console.log($("a[role='tab']").length); + +var q_array=$("a[role='tab']") +//console.log($(q_array[0]).attr('href')); +var i =0; +while(i',{style:'width:20px;height:20px',src:dialog_url})); + j++; +} \ No newline at end of file diff --git a/student_view.css b/student_view.css new file mode 100644 index 0000000..e69de29 diff --git a/suggestions.css b/suggestions.css index eeaa1d5..f0b1b5a 100644 --- a/suggestions.css +++ b/suggestions.css @@ -78,4 +78,56 @@ width: 100%; height: 100%; overflow-y: scroll; -} \ No newline at end of file +} + +input[type=checkbox]{ + display: inline-block; + position: inherit !important; + -webkit-appearance: checkbox !important; +} + +a[disabled="disabled"] { + opacity: 0.5; + pointer-events: none; + cursor: default; +} + + +.suggestion_container_pdf{ + position: absolute; + z-index: 9; + padding-top: 80px; + padding-left: 0px; + width:190px; +} + +#mydivheader { + padding: 10px; + cursor: move; + z-index: 10; + width:190px; + background-color: #2196F3; + color: #fff; +} + +.suggestion_box_pdf { + width:150px; + border: 1px solid #004ea3 !important; + height: 200px !important; + overflow-y: scroll !important; + background-color: rgb(248, 248, 245) !important; + position: relative !important; + pointer-events: auto !important; + width:190px; +} + +.btn_pdf{ + pointer-events:auto !important; +} + +.anchor_on_right{ + font-style:oblique; + display: block; + +} +