-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaste.js
2 lines (2 loc) · 7.65 KB
/
paste.js
1
2
/*! For license information please see paste.js.LICENSE.txt */
(()=>{function t(t,n){if(document.getElementById(`weight_${t.replace(/\s+/g,"_")}`))return;const o=document.createElement("div");o.style.marginBottom="10px";const r=document.createElement("label");r.textContent=`${t}: `,r.className="weight-label",r.style.marginRight="10px";const i=document.createElement("input");i.type="number",i.value="1",i.min=0,i.step=.1,i.className="weight-input",i.id=`weight_${t.replace(/\s+/g,"_")}`,i.title="Set the weight for this category (e.g. 0.4 for 40%)",i.addEventListener("input",e),o.appendChild(r),o.appendChild(i),n.appendChild(o)}function e(){const t=document.querySelectorAll("td.score input"),e={};let n=0,o=0;const r=document.querySelector('#whatIfControlsContainer input[type="checkbox"]'),i=r&&r.checked;document.querySelectorAll("#weightContainer input").forEach((t=>{const n=t.id.replace("weight_","").replace(/_/g," "),o=parseFloat(t.value);e[n]=isNaN(o)||o<0?1:o}));const d={};let a=0,l=0;t.forEach((t=>{const e=t.closest("tr"),n=e.querySelector("td:nth-child(2) .ng-binding")||e.querySelector("td:nth-child(2) select")||e.querySelector("td:nth-child(2) input"),o=n?.value?.trim?.()||n?.textContent?.trim?.()||"",r=t.value.trim().split("/");if(2===r.length){const t=parseFloat(r[0]),e=parseFloat(r[1]);!isNaN(t)&&!isNaN(e)&&e>0&&(d[o]||(d[o]={totalEarned:0,totalPossible:0}),d[o].totalEarned+=t,d[o].totalPossible+=e,a+=t,l+=e)}}));let c="--";if(i){for(const t in d){const r=d[t],i=r.totalPossible>0?r.totalEarned/r.totalPossible:0,a=e[t]||1;n+=i*a,o+=a}o>0&&(c=(n/o*100).toFixed(2)+"%")}else l>0&&(c=(a/l*100).toFixed(2)+"%");const s=document.querySelector("table.linkDescList td:nth-child(5)");if(s){const t=s.textContent.trim(),e=t.match(/(\d+\.\d+%)/),n=e?e[0]:t;s.innerHTML=`${n} <span style="color:#007acc;font-weight:bold;">(${c} What-If)</span>`}}function n(){const t=document.getElementById("scoreTable");if(!t)return;const n=t.querySelector("tbody");if(!n)return;const o=`\n <select class="score-input">\n ${i.map((t=>`<option value="${t}">${t}</option>`)).join("")}\n </select>\n `,r=document.createElement("tr");r.setAttribute("data-ng-repeat-start",""),r.innerHTML=`\n <td>\n <input\n type="text"\n class="score-input"\n placeholder="Date (e.g. 10/01)"\n />\n </td>\n <td>\n ${o}\n </td>\n <td>\n <input\n type="text"\n class="score-input"\n placeholder="Assignment"\n />\n </td>\n <td colspan="7" class="text-center"></td>\n <td class="score text-center">\n <span class="ng-binding">\n <input\n type="text"\n class="score-input"\n placeholder="e.g. 8/10"\n title="Enter earned/possible points"\n />\n </span>\n </td>\n <td class="text-center">\n <span class="ng-binding">--</span>\n </td>\n <td class="text-center">\n <span class="ng-binding">--</span>\n </td>\n <td class="text-center">\n <button class="delete-row-btn" style="padding: 4px 8px;">\n Delete\n </button>\n </td>\n `,n.prepend(r);const d=r.querySelector("td.score input");d&&d.addEventListener("input",e);const a=r.querySelector("td:nth-child(2) select");a&&a.addEventListener("change",e),r.querySelector(".delete-row-btn").addEventListener("click",(()=>{r.remove(),e()})),e()}function o(){const n=prompt("Enter new category name:");if(!n)return;const o=n.trim();if(!o)return;if(i.includes(o))return void alert(`Category "${o}" already exists.`);i.push(o);const r=document.getElementById("weightContainer");r&&t(o,r),document.querySelectorAll("tr[data-ng-repeat-start] td:nth-child(2) select.score-input").forEach((t=>{const e=new Option(o,o);t.add(e)})),e()}const r=document.createElement("style");r.textContent="\n#whatIfControlsContainer {\n border: 1px solid #ddd;\n padding: 20px;\n margin-bottom: 20px;\n background: #f9f9f9;\n font-family: Arial, sans-serif;\n}\n#whatIfControlsContainer h3 {\n margin-top: 0;\n font-family: Arial, sans-serif;\n font-size: 18px;\n}\n.score-input, .weight-input {\n padding: 5px;\n font-size: 14px;\n width: 80px;\n border: 1px solid #ccc;\n border-radius: 4px;\n}\n.weight-label {\n font-size: 14px;\n font-weight: bold;\n}\n#weightContainer label {\n display: inline-block;\n width: 150px;\n text-align: right;\n}\n#weightContainer input {\n margin-left: 10px;\n}\n#addGradeBtn, #addCategoryBtn {\n margin-top: 0 !important;\n}\n.delete-row-btn {\n background: #f44336;\n color: #fff;\n border: none;\n cursor: pointer;\n border-radius: 4px;\n}\n.delete-row-btn:hover {\n background: #d32f2f;\n}\n",document.head.appendChild(r);const i=[...new Set(function(){const t=document.getElementById("scoreTable");if(!t)return[];const e=t.querySelectorAll("tbody tr[data-ng-repeat-start]"),n=[];return e.forEach((t=>{const e=t.querySelector("td:nth-child(1)"),o=t.querySelector("td:nth-child(2) .ng-binding"),r=t.querySelector("td:nth-child(3) .ng-binding"),i=t.querySelector("td.score .ng-binding"),d=t.querySelector("span.weightedScore"),a=t.querySelector('td[data-ng-if*="showPercentGrade"]'),l=t.querySelector('td[data-ng-if*="showLetterGrade"]'),c=(e?.textContent||"").trim(),s=(o?.textContent||"").trim(),p=(r?.textContent||"").trim(),u=i?i.textContent.trim():"--",m=d?d.textContent.trim():"",h=a?a.textContent.trim():"--",g=l?l.textContent.trim():"--";n.push([c,s,p,u,m,h,g])})),n}().map((t=>t[1])))];!function(r){const i=document.querySelector("table.linkDescList");if(!i)return;const d=document.createElement("div");d.id="whatIfControlsContainer";const a=document.createElement("h3");a.textContent="What-If Scenario Calculator",a.style.marginBottom="10px",d.appendChild(a);const l=document.createElement("p");l.textContent='Use the tools below to adjust assignment scores and set category weights to see a "What-If" final grade.',l.style.marginBottom="20px",l.style.fontSize="14px",d.appendChild(l);const c=document.createElement("div");c.style.marginBottom="20px";const s=document.createElement("label");s.textContent="Use Weighted Calculation: ",s.style.fontWeight="bold",s.style.display="inline-block",s.style.marginRight="10px";const p=document.createElement("input");p.type="checkbox",p.checked=!1,p.addEventListener("change",e),s.appendChild(p),c.appendChild(s),d.appendChild(c);const u=document.createElement("fieldset"),m=document.createElement("legend");m.textContent="Category Weights (Only if weighted calc is enabled)",m.style.fontWeight="bold",m.style.fontSize="14px",m.style.marginBottom="10px",u.appendChild(m),u.style.border="1px solid #ccc",u.style.padding="10px",u.style.marginBottom="20px";const h=document.createElement("div");h.id="weightContainer",r.forEach((e=>{t(e,h)})),u.appendChild(h),d.appendChild(u);const g=document.createElement("div");g.style.display="flex",g.style.gap="10px";const y=document.createElement("button");y.id="addGradeBtn",y.type="button",y.textContent="+ Add New Grade",y.style.marginTop="10px",y.addEventListener("click",n);const f=document.createElement("button");f.id="addCategoryBtn",f.type="button",f.textContent="+ Add Category",f.style.marginTop="10px",f.addEventListener("click",o),g.appendChild(y),g.appendChild(f),d.appendChild(g),i.parentElement.insertBefore(d,i)}(i),document.querySelectorAll("tbody tr[data-ng-repeat-start]").forEach((t=>{const n=t.querySelector("td.score .ng-binding");let o=t.querySelector("span.weightedScore")||n;if(!o)return;if(o.querySelector("input"))return;const r=o.textContent.trim(),i=r.match(/(\d+(\.\d+)?\/\d+(\.\d+)?)/),d=i?i[0]:r,a=document.createElement("input");a.type="text",a.value=d,a.className="score-input",a.title='Enter earned/possible points (e.g. "8/10")',a.placeholder="e.g. 8/10",a.addEventListener("input",e),o.textContent="",o.appendChild(a)})),e()})();