Last active
May 17, 2024 04:15
-
-
Save viethung0823/999baacb99fe2a58c7691a444dc982b0 to your computer and use it in GitHub Desktop.
PTIT Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function selectElementText(e,t=document){let n=t.querySelector(e),o=document.createRange();o.selectNodeContents(n);let l=window.getSelection();return l.removeAllRanges(),l.addRange(o),window.getSelection().toString().replace(/\n/g," ").trim()}if(window.location.href.includes("mod/quiz/review.php?attempt")){const e=document.querySelectorAll(".que");let t="";Array.from(e).forEach((e=>{const n=selectElementText(".qtext p",e),o=n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),l=selectElementText(".rightanswer p",e);t+=`"${o}", "${n}", "${l}"\n`}));const n={data:t};fetch("https://ptit-pool-data.vercel.app/update-sheet",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then((e=>e.json())).then((e=>{console.log(e)})).catch((e=>{console.error("Error:",e)})),GM_setClipboard(t)}else if(window.location.href.includes("mod/quiz/attempt.php?attempt")){const e=document.querySelectorAll(".que");let t="";Array.from(e).forEach((async(e,n)=>{const o=e.querySelector(".qtext p"),l=selectElementText(".qtext p",e);let r="";const a=l.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"");if(o){const e=document.createElement("a");e.textContent="Check Answer",e.href=`https://ptit-pool-data.vercel.app/api/question/${encodeURIComponent(a)}`,e.style.marginLeft="10px",o.appendChild(e);const t=await fetch(`https://ptit-pool-data.vercel.app/api/question/${encodeURIComponent(a)}`),n=await t.json();r=n.data[2]}const c=e.querySelectorAll(".answer .d-flex"),p=Array.from(c).map((e=>{const t=selectElementText(".answernumber",e),n=selectElementText(".flex-fill p",e);if(n===r){e.previousElementSibling.click()}return`${t} ${n}`}));t+=`Question ${n+1}: ${l}\n\n${p.join("\n")}\n\n`})),GM_setClipboard(t)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment