1+ const copyToClipboard = async ( text ) => {
2+ try {
3+ await navigator . clipboard . writeText ( text ) ;
4+ } catch ( err ) {
5+ console . error ( 'Failed to copy to clipboard' , err ) ;
6+ throw err ;
7+ }
8+ } ;
9+
10+ const waitForPageLoad = ( ) => {
11+ return new Promise ( ( resolve , reject ) => {
12+ const checkReadyState = ( ) => {
13+ if ( document . readyState === 'complete' ) {
14+ resolve ( ) ;
15+ } else {
16+ setTimeout ( checkReadyState , 1000 ) ;
17+ }
18+ } ;
19+
20+ checkReadyState ( ) ;
21+ } ) ;
22+ } ;
23+
24+ waitForPageLoad ( ) . then ( ( ) => {
25+ if ( window . location . href . includes ( "online_review/mock_clerk.php" ) ) {
26+ const questions = document . querySelectorAll ( 'table.quest' ) ;
27+ toast ( 'Questions is loaded' ) ;
28+
29+ const processQuestions = async ( ) => {
30+ let output = '' ;
31+ for ( let index = 0 ; index < questions . length ; index ++ ) {
32+ const question = questions [ index ] ;
33+ const questionTextElement = question . querySelector ( 'div.singlequesimg' ) ;
34+ let questionText = questionTextElement ? questionTextElement . innerText . replace ( / \s \s + / g, '\n' ) . trim ( ) : '' ;
35+
36+ const questionImg = questionTextElement . querySelector ( 'img' ) ;
37+ if ( questionImg ) {
38+ const questionImgSrc = questionImg . getAttribute ( 'src' ) ;
39+ questionText += `\n<img src="${ questionImgSrc } " alt="sauravhathi" />` ;
40+ }
41+
42+ const shortQuestionTextElement = question . querySelector ( 'tr td.text_1 div div span' ) ;
43+ if ( shortQuestionTextElement ) {
44+ questionText += `\n\n${ shortQuestionTextElement . innerText } ` ;
45+ }
46+
47+ const optionsElements = question . querySelectorAll ( 'table' ) ;
48+ const options = [ ...optionsElements ] . map ( optionElement => {
49+ const optionTextElement = optionElement . querySelector ( 'label' ) ;
50+ return optionTextElement ? optionTextElement . textContent . trim ( ) : '' ;
51+ } ) ;
52+
53+ const explanationElement = question . querySelector ( '.explanation_div' ) ;
54+ let explanationContent = '' ;
55+
56+ if ( explanationElement ) {
57+ explanationContent = explanationElement . innerText . replace ( / \s \s + / g, '\n' ) . replace ( 'Explanation' , '<b>Explanation:</b>' ) . trim ( ) ;
58+
59+ const imgElement = explanationElement . querySelector ( 'img' ) ;
60+ if ( imgElement ) {
61+ const imgSrc = imgElement . getAttribute ( 'src' ) ;
62+ explanationContent += `\n<img src="${ imgSrc } " alt="sauravhathi" />` ;
63+ }
64+ }
65+
66+ const correctAnswerElement = question . querySelector ( '.corect_ans p span' ) ;
67+ const correctAnswer = correctAnswerElement ? correctAnswerElement . textContent . trim ( ) : '' ;
68+
69+ output += `<b>Question ${ index + 1 } :</b>\n${ questionText } \n\n<b>Options:</b>\n${ options . map ( ( option , optionIndex ) => `${ String . fromCharCode ( 65 + optionIndex ) } . ${ option } ` ) . join ( '\n' ) } \n\n${ explanationContent } \n\n<b>Correct Answer:</b> ${ correctAnswer } \n\n` ;
70+ }
71+ console . log ( output ) ;
72+ await copyToClipboard ( output ) ;
73+ toast ( 'Copied all questions to clipboard' ) ;
74+ } ;
75+ processQuestions ( ) ;
76+ }
77+ } ) ;
0 commit comments