11// answer.js
2- // v1.0 .0
2+ // v1.1 .0
33// Made by mmccall0813 on github
44// https://www.github.com/mmccall0813/answer.js
55// dont steal pls!
@@ -36,17 +36,17 @@ joinButton.onclick = function(...args){
3636 form . onsubmit ( )
3737}
3838async function start ( gameid ) {
39- var answers = { } ;
39+ var answers = [ ] ;
4040 var mode = "" ;
4141 fetch ( "https://fb.blooket.com/c/firebase/join" , {
4242 "body" : `{\"id\":\"${ gameid } \",\"name\":\"answerdotjs\"}` ,
4343 "method" : "PUT" ,
4444 "mode" : "cors"
4545 } ) . then ( async ( res ) => {
4646 var json = await res . json ( ) ;
47- console . log ( `Set id is ${ json . host . set } ` ) ;
48- console . log ( `Game pin is ${ gameid } ` )
49- console . log ( `Game mode is ${ json . host . s . t } ` ) ;
47+ console . info ( `Set id is ${ json . host . set } ` ) ;
48+ console . info ( `Game pin is ${ gameid } ` ) ;
49+ console . info ( `Game mode is ${ json . host . s . t } ` ) ;
5050 mode = json . host . s . t ;
5151 console . log ( "Getting game answers..." ) ;
5252 var gameinfo = await fetch ( `https://api.blooket.com/api/games?gameId=${ json . host . set } ` ) ;
@@ -58,12 +58,16 @@ async function start(gameid){
5858 q . correctAnswers [ 0 ] = q . correctAnswers [ 0 ] . trim ( ) . replace ( / + (? = ) / g, '' ) ;
5959 // note to self: rewrite this to support image matching
6060 // questions can have the same text, but different images
61- answers [ q . question ] = {
61+ var hasImage = false ;
62+ if ( typeof q . image == "object" ) hasImage = true ;
63+ answers . push ( {
6264 num :q . number ,
6365 text :q . question ,
6466 possibleAnswers :q . answers ,
65- correctAnswers :q . correctAnswers
66- }
67+ correctAnswers :q . correctAnswers ,
68+ hasImage : hasImage ,
69+ image : q . image
70+ } ) ;
6771 } )
6872 } )
6973 var cryptoPasswords = { } ;
@@ -78,15 +82,15 @@ async function start(gameid){
7882 var header = document . querySelector ( "[class^='styles__headerInside___']" ) ;
7983 if ( header && header . innerText ) document . querySelector ( "[class^='arts__regularBody___']" ) . click ( )
8084 // after you select a chest, go to the next screen
81-
85+
8286 var noPlayersNext = document . querySelector ( "[class^='styles__noPlayers___'] > div" ) ;
8387 if ( noPlayersNext ) noPlayersNext . click ( ) ;
8488 // if theres no players to swap with or steal from, hit the button to go to the next screen
8589
8690 var firstPlayerToSteal = document . querySelector ( "[class^='styles__playerContainer___']" ) ;
8791 if ( firstPlayerToSteal ) firstPlayerToSteal . click ( ) ; // might swap with lower player if its a swap
8892 // steal from players
89-
93+
9094 break ;
9195 case "Hack" : // crypto hack auto-play
9296 var passwords = document . querySelectorAll ( "[class^='styles__button___']" ) ;
@@ -95,9 +99,9 @@ async function start(gameid){
9599 // choose a randomized password
96100
97101 var feedbackText = document . querySelector ( "[class^='styles__nextText___']" ) ;
98- if ( feedbackText ) feedbackText . parentElement . click ( ) ;
102+ if ( feedbackText ) feedbackText . parentElement . click ( ) ;
99103 // automatically click next after getting question correct
100-
104+
101105 var outputs = document . querySelectorAll ( "[class^=\"styles__choice__\"]" ) ;
102106 if ( outputs . length == 3 ) outputs [ Math . floor ( Math . random ( ) * outputs . length ) ] . click ( ) ;
103107 // auto choose a random output
@@ -134,7 +138,7 @@ async function start(gameid){
134138 } )
135139 if ( correct ) correct . click ( )
136140 }
137-
141+
138142 var status = "" ;
139143 var result = document . querySelectorAll ( "[class^='styles__introHeader___']" ) . forEach ( ( e ) => {
140144 if ( e . innerText == "CORRECT" ) {
@@ -160,7 +164,7 @@ async function start(gameid){
160164 var questionText = document . querySelector ( "[class^='styles__questionText___']" )
161165 if ( questionText && questionText . innerText ) ; else return ;
162166 var question = answers [ questionText . innerText ] ;
163-
167+
164168 var answered = false ;
165169 for ( var i = 0 ; i < 4 && answered == false ; i ++ ) {
166170 var button = document . querySelectorAll ( "[class^='styles__answerContainer___']" ) [ i ] ;
@@ -180,10 +184,20 @@ async function start(gameid){
180184 }
181185 var questionText = document . querySelector ( "[class^='styles__questionText___']" )
182186 var feedback = document . querySelector ( "[class^='styles__feedbackContainer___'] > div" ) ;
187+ var img = document . querySelector ( "[class^='styles__image___']" ) ;
188+ var hasImage = img !== null ;
189+ var imgID = hasImage ? img . src . split ( "/" ) [ img . src . split ( "/" ) . length - 1 ] . split ( "." ) [ 0 ] : undefined ;
183190 if ( feedback ) feedback . click ( ) ;
184191 if ( questionText && questionText . innerText ) ; else return ;
185- var question = answers [ questionText . innerText ] ;
186-
192+
193+ var question = answers . filter ( ( ques , index ) => {
194+ if ( hasImage ) {
195+ return ques . hasImage == true && ques . image . id == imgID && ques . text == questionText . innerText ;
196+ } else {
197+ return ques . text == questionText . innerText
198+ }
199+ } ) [ 0 ] ;
200+
187201 var answered = false ;
188202 for ( var i = 0 ; i < 4 && answered == false ; i ++ ) {
189203 var button = document . querySelectorAll ( "[class^='styles__answerContainer___']" ) [ i ] ;
0 commit comments