Best K6 code snippet using html.TextContent
Start.go
Source:Start.go
1package main2import (3 "fmt"4 "net/http"5)6func Home(w http.ResponseWriter, r *http.Request) {7 html := `<head> 8 9 <script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>10 </head> 11 <html>12 <body style=background-color:black>13 14<div id='result' style=background-color:black;border-color:black;color:white;position:absolute;font-size:2em;left:15em;top:0em;><h3></h3></div><br><br>15 16<form action="{{.html}}">17<button type="submit" id="re" style=position:absolute;left:58em;top:2em;width:11em;height:5em;color:white;background-color:black>Retry</button>18</form> 19<form action="receive" method="post" id="cf1">20<button type="button" id="cl1" style=color:black;background-color:white;position:absolute;top:10em;left:37em;width:10em;height:9em;></button>21</form>22<form action="receive" method="post" id="cf2">23<button type="button" id="cl2" style=color:black;background-color:white;position:absolute;top:10em;left:48em;width:10em;height:9em;></button>24</form>25<form action="receive" method="post" id="cf3">26<button type="button" id="cl3" style=color:black;background-color:white;position:absolute;top:10em;left:59em;width:10em;height:9em;></button>27</form>28<form action="receive" method="post" id="cf6">29<button type="button" id="cl6" style=color:black;background-color:white;position:absolute;top:20em;left:59em;width:10em;height:9em;></button>30</form>31<form action="receive" method="post" id="cf5">32<button type="button" id="cl5" style=color:black;background-color:white;position:absolute;top:20em;left:48em;width:10em;height:9em;></button>33</form>34<form action="receive" method="post" id="cf4">35<button type="button" id="cl4" style=color:black;background-color:white;position:absolute;top:20em;left:37em;width:10em;height:9em;></button>36</form>37<form action="receive" method="post" id="cf7">38<button type="button" id="cl7" style=color:black;background-color:white;position:absolute;top:30em;left:37em;width:10em;height:9em;></button>39</form>40<form action="receive" method="post" id="cf8">41<button type="button" id="cl8" style=color:black;background-color:white;position:absolute;top:30em;left:48em;width:10em;height:9em;></button>42</form>43<form action="receive" method="post" id="cf9">44<button type="button" id="cl9" style=color:black;background-color:white;position:absolute;left:59em;width:10em;height:9em;top:30em;></button>45</form>46 </body></html>47<script>48$('#cl1').click(function(){49 if($('#result h2').text()==""){50 if (document.getElementById("cl1").textContent==""){51 document.getElementById("cl1").innerHTML="X";52 if(document.getElementById("cl2").textContent=="X"){53 if(document.getElementById("cl3").textContent==""){54 document.getElementById("cl3").innerHTML="O";55 }else if (document.getElementById("cl2").textContent==""){56 document.getElementById("cl2").innerHTML="O";57 }else if(document.getElementById("cl3").textContent==""){58 document.getElementById("cl3").innerHTML="O";59 }else if(document.getElementById("cl4").textContent==""){60 document.getElementById("cl4").innerHTML="O";61 }else if(document.getElementById("cl5").textContent==""){62 document.getElementById("cl5").innerHTML="O";63 }else if(document.getElementById("cl6").textContent==""){64 document.getElementById("cl6").innerHTML="O";65 }else if(document.getElementById("cl7").textContent==""){66 document.getElementById("cl7").innerHTML="O";67 }else if(document.getElementById("cl8").textContent==""){68 document.getElementById("cl8").innerHTML="O";69 }else if(document.getElementById("cl9").textContent==""){70 document.getElementById("cl9").innerHTML="O";71 }72 }else if(document.getElementById("cl4").textContent=="X"){73 if(document.getElementById("cl7").textContent==""){74 document.getElementById("cl7").innerHTML="O";75 }else if (document.getElementById("cl2").textContent==""){76 document.getElementById("cl2").innerHTML="O";77 }else if(document.getElementById("cl3").textContent==""){78 document.getElementById("cl3").innerHTML="O";79 }else if(document.getElementById("cl4").textContent==""){80 document.getElementById("cl4").innerHTML="O";81 }else if(document.getElementById("cl5").textContent==""){82 document.getElementById("cl5").innerHTML="O";83 }else if(document.getElementById("cl6").textContent==""){84 document.getElementById("cl6").innerHTML="O";85 }else if(document.getElementById("cl7").textContent==""){86 document.getElementById("cl7").innerHTML="O";87 }else if(document.getElementById("cl8").textContent==""){88 document.getElementById("cl8").innerHTML="O";89 }else if(document.getElementById("cl9").textContent==""){90 document.getElementById("cl9").innerHTML="O";91 }92 }else if(document.getElementById("cl3").textContent=="X" && document.getElementById("cl1").textContent=="X"){93 if(document.getElementById("cl2").textContent==""){94 document.getElementById("cl2").innerHTML="O";95 }else if (document.getElementById("cl2").textContent==""){96 document.getElementById("cl2").innerHTML="O";97 }else if(document.getElementById("cl3").textContent==""){98 document.getElementById("cl3").innerHTML="O";99 }else if(document.getElementById("cl4").textContent==""){100 document.getElementById("cl4").innerHTML="O";101 }else if(document.getElementById("cl5").textContent==""){102 document.getElementById("cl5").innerHTML="O";103 }else if(document.getElementById("cl6").textContent==""){104 document.getElementById("cl6").innerHTML="O";105 }else if(document.getElementById("cl7").textContent==""){106 document.getElementById("cl7").innerHTML="O";107 }else if(document.getElementById("cl8").textContent==""){108 document.getElementById("cl8").innerHTML="O";109 }else if(document.getElementById("cl9").textContent==""){110 document.getElementById("cl9").innerHTML="O";111 }112 }else if(document.getElementById("cl7").textContent=="X" && document.getElementById("cl1").textContent=="X"){113 if(document.getElementById("cl4").textContent==""){114 document.getElementById("cl4").innerHTML="O";115 }else if (document.getElementById("cl2").textContent==""){116 document.getElementById("cl2").innerHTML="O";117 }else if(document.getElementById("cl3").textContent==""){118 document.getElementById("cl3").innerHTML="O";119 }else if(document.getElementById("cl4").textContent==""){120 document.getElementById("cl4").innerHTML="O";121 }else if(document.getElementById("cl5").textContent==""){122 document.getElementById("cl5").innerHTML="O";123 }else if(document.getElementById("cl6").textContent==""){124 document.getElementById("cl6").innerHTML="O";125 }else if(document.getElementById("cl7").textContent==""){126 document.getElementById("cl7").innerHTML="O";127 }else if(document.getElementById("cl8").textContent==""){128 document.getElementById("cl8").innerHTML="O";129 }else if(document.getElementById("cl9").textContent==""){130 document.getElementById("cl9").innerHTML="O";131 }132 133 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl1").textContent=="X"){134 if(document.getElementById("cl5").textContent==""){135 document.getElementById("cl5").innerHTML="O";136 }else if (document.getElementById("cl2").textContent==""){137 document.getElementById("cl2").innerHTML="O";138 }else if(document.getElementById("cl3").textContent==""){139 document.getElementById("cl3").innerHTML="O";140 }else if(document.getElementById("cl4").textContent==""){141 document.getElementById("cl4").innerHTML="O";142 }else if(document.getElementById("cl5").textContent==""){143 document.getElementById("cl5").innerHTML="O";144 }else if(document.getElementById("cl6").textContent==""){145 document.getElementById("cl6").innerHTML="O";146 }else if(document.getElementById("cl7").textContent==""){147 document.getElementById("cl7").innerHTML="O";148 }else if(document.getElementById("cl8").textContent==""){149 document.getElementById("cl8").innerHTML="O";150 }else if(document.getElementById("cl9").textContent==""){151 document.getElementById("cl9").innerHTML="O";152 }153 154 }else if (document.getElementById("cl2").textContent==""){155 document.getElementById("cl2").innerHTML="O";156 }else if(document.getElementById("cl3").textContent==""){157 document.getElementById("cl3").innerHTML="O";158 }else if(document.getElementById("cl4").textContent==""){159 document.getElementById("cl4").innerHTML="O";160 }else if(document.getElementById("cl5").textContent==""){161 document.getElementById("cl5").innerHTML="O";162 }else if(document.getElementById("cl6").textContent==""){163 document.getElementById("cl6").innerHTML="O";164 }else if(document.getElementById("cl7").textContent==""){165 document.getElementById("cl7").innerHTML="O";166 }else if(document.getElementById("cl8").textContent==""){167 document.getElementById("cl8").innerHTML="O";168 }else if(document.getElementById("cl9").textContent==""){169 document.getElementById("cl9").innerHTML="O";170 }171 } else {172 alert("try another squre");173 }174 }else{175 alert("Please try again");176 }177})178$('#cl2').click(function(){179if($('#result h2').text()==""){180if (document.getElementById("cl2").textContent==""){181 document.getElementById("cl2").innerHTML="X";182 if(document.getElementById("cl1").textContent=="X"){183 if(document.getElementById("cl3").textContent==""){184 document.getElementById("cl3").innerHTML="O";185 }else if (document.getElementById("cl1").textContent==""){186 document.getElementById("cl1").innerHTML="O";187 }else if(document.getElementById("cl3").textContent==""){188 document.getElementById("cl3").innerHTML="O";189 }else if(document.getElementById("cl4").textContent==""){190 document.getElementById("cl4").innerHTML="O";191 }else if(document.getElementById("cl5").textContent==""){192 document.getElementById("cl5").innerHTML="O";193 }else if(document.getElementById("cl6").textContent==""){194 document.getElementById("cl6").innerHTML="O";195 }else if(document.getElementById("cl7").textContent==""){196 document.getElementById("cl7").innerHTML="O";197 }else if(document.getElementById("cl8").textContent==""){198 document.getElementById("cl8").innerHTML="O";199 }else if(document.getElementById("cl9").textContent==""){200 document.getElementById("cl9").innerHTML="O";201 }202 }else if(document.getElementById("cl3").textContent=="X"){203 if(document.getElementById("cl1").textContent==""){204 document.getElementById("cl1").innerHTML="O";205 }else if (document.getElementById("cl1").textContent==""){206 document.getElementById("cl1").innerHTML="O";207 }else if(document.getElementById("cl3").textContent==""){208 document.getElementById("cl3").innerHTML="O";209 }else if(document.getElementById("cl4").textContent==""){210 document.getElementById("cl4").innerHTML="O";211 }else if(document.getElementById("cl5").textContent==""){212 document.getElementById("cl5").innerHTML="O";213 }else if(document.getElementById("cl6").textContent==""){214 document.getElementById("cl6").innerHTML="O";215 }else if(document.getElementById("cl7").textContent==""){216 document.getElementById("cl7").innerHTML="O";217 }else if(document.getElementById("cl8").textContent==""){218 document.getElementById("cl8").innerHTML="O";219 }else if(document.getElementById("cl9").textContent==""){220 document.getElementById("cl9").innerHTML="O";221 }222 }else if(document.getElementById("cl5").textContent=="X" && document.getElementById("cl2").textContent=="X"){223 if(document.getElementById("cl8").textContent==""){224 document.getElementById("cl8").innerHTML="O";225 }else if (document.getElementById("cl1").textContent==""){226 document.getElementById("cl1").innerHTML="O";227 }else if(document.getElementById("cl3").textContent==""){228 document.getElementById("cl3").innerHTML="O";229 }else if(document.getElementById("cl4").textContent==""){230 document.getElementById("cl4").innerHTML="O";231 }else if(document.getElementById("cl5").textContent==""){232 document.getElementById("cl5").innerHTML="O";233 }else if(document.getElementById("cl6").textContent==""){234 document.getElementById("cl6").innerHTML="O";235 }else if(document.getElementById("cl7").textContent==""){236 document.getElementById("cl7").innerHTML="O";237 }else if(document.getElementById("cl8").textContent==""){238 document.getElementById("cl8").innerHTML="O";239 }else if(document.getElementById("cl9").textContent==""){240 document.getElementById("cl9").innerHTML="O";241 }242 }else if(document.getElementById("cl8").textContent=="X" && document.getElementById("cl2").textContent=="X"){243 if(document.getElementById("cl5").textContent==""){244 document.getElementById("cl5").innerHTML="O";245 }else if (document.getElementById("cl1").textContent==""){246 document.getElementById("cl1").innerHTML="O";247 }else if(document.getElementById("cl3").textContent==""){248 document.getElementById("cl3").innerHTML="O";249 }else if(document.getElementById("cl4").textContent==""){250 document.getElementById("cl4").innerHTML="O";251 }else if(document.getElementById("cl5").textContent==""){252 document.getElementById("cl5").innerHTML="O";253 }else if(document.getElementById("cl6").textContent==""){254 document.getElementById("cl6").innerHTML="O";255 }else if(document.getElementById("cl7").textContent==""){256 document.getElementById("cl7").innerHTML="O";257 }else if(document.getElementById("cl8").textContent==""){258 document.getElementById("cl8").innerHTML="O";259 }else if(document.getElementById("cl9").textContent==""){260 document.getElementById("cl9").innerHTML="O";261 }262 }else if (document.getElementById("cl1").textContent==""){263 document.getElementById("cl1").innerHTML="O";264 }else if(document.getElementById("cl3").textContent==""){265 document.getElementById("cl3").innerHTML="O";266 }else if(document.getElementById("cl4").textContent==""){267 document.getElementById("cl4").innerHTML="O";268 }else if(document.getElementById("cl5").textContent==""){269 document.getElementById("cl5").innerHTML="O";270 }else if(document.getElementById("cl6").textContent==""){271 document.getElementById("cl6").innerHTML="O";272 }else if(document.getElementById("cl7").textContent==""){273 document.getElementById("cl7").innerHTML="O";274 }else if(document.getElementById("cl8").textContent==""){275 document.getElementById("cl8").innerHTML="O";276 }else if(document.getElementById("cl9").textContent==""){277 document.getElementById("cl9").innerHTML="O";278 }279 } else {280 alert("try another squre");281 }282 }else{283 alert("Please try again")284 }285})286$('#cl3').click(function(){287if($('#result h2').text()==""){288if (document.getElementById("cl3").textContent==""){289 document.getElementById("cl3").innerHTML="X";290 if(document.getElementById("cl2").textContent=="X"){291 if(document.getElementById("cl1").textContent==""){292 document.getElementById("cl1").innerHTML="O";293 }else if (document.getElementById("cl1").textContent==""){294 document.getElementById("cl1").innerHTML="O";295 }else if(document.getElementById("cl2").textContent==""){296 document.getElementById("cl2").innerHTML="O";297 }else if(document.getElementById("cl4").textContent==""){298 document.getElementById("cl4").innerHTML="O";299 }else if(document.getElementById("cl5").textContent==""){300 document.getElementById("cl5").innerHTML="O";301 }else if(document.getElementById("cl6").textContent==""){302 document.getElementById("cl6").innerHTML="O";303 }else if(document.getElementById("cl7").textContent==""){304 document.getElementById("cl7").innerHTML="O";305 306 }else if(document.getElementById("cl8").textContent==""){307 document.getElementById("cl8").innerHTML="O";308 }else if(document.getElementById("cl9").textContent==""){309 document.getElementById("cl9").innerHTML="O";310 }311 }else if(document.getElementById("cl6").textContent=="X"){312 if(document.getElementById("cl9").textContent==""){313 document.getElementById("cl9").innerHTML="O";314 }else if (document.getElementById("cl1").textContent==""){315 document.getElementById("cl1").innerHTML="O";316 }else if(document.getElementById("cl2").textContent==""){317 document.getElementById("cl2").innerHTML="O";318 }else if(document.getElementById("cl4").textContent==""){319 document.getElementById("cl4").innerHTML="O";320 }else if(document.getElementById("cl5").textContent==""){321 document.getElementById("cl5").innerHTML="O";322 }else if(document.getElementById("cl6").textContent==""){323 document.getElementById("cl6").innerHTML="O";324 }else if(document.getElementById("cl7").textContent==""){325 document.getElementById("cl7").innerHTML="O";326 }else if(document.getElementById("cl8").textContent==""){327 document.getElementById("cl8").innerHTML="O";328 }else if(document.getElementById("cl9").textContent==""){329 document.getElementById("cl9").innerHTML="O";330 }331 }else if(document.getElementById("cl3").textContent=="X" && document.getElementById("cl1").textContent=="X"){332 if(document.getElementById("cl2").textContent==""){333 document.getElementById("cl2").innerHTML="O";334 }else if (document.getElementById("cl1").textContent==""){335 document.getElementById("cl1").innerHTML="O";336 }else if(document.getElementById("cl2").textContent==""){337 document.getElementById("cl2").innerHTML="O";338 }else if(document.getElementById("cl4").textContent==""){339 document.getElementById("cl4").innerHTML="O";340 }else if(document.getElementById("cl5").textContent==""){341 document.getElementById("cl5").innerHTML="O";342 }else if(document.getElementById("cl6").textContent==""){343 document.getElementById("cl6").innerHTML="O";344 }else if(document.getElementById("cl7").textContent==""){345 document.getElementById("cl7").innerHTML="O";346 }else if(document.getElementById("cl8").textContent==""){347 document.getElementById("cl8").innerHTML="O";348 }else if(document.getElementById("cl9").textContent==""){349 document.getElementById("cl9").innerHTML="O";350 }351 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl3").textContent=="X"){352 if(document.getElementById("cl6").textContent==""){353 document.getElementById("cl6").innerHTML="O";354 }else if (document.getElementById("cl1").textContent==""){355 document.getElementById("cl1").innerHTML="O";356 }else if(document.getElementById("cl2").textContent==""){357 document.getElementById("cl2").innerHTML="O";358 }else if(document.getElementById("cl4").textContent==""){359 document.getElementById("cl4").innerHTML="O";360 }else if(document.getElementById("cl5").textContent==""){361 document.getElementById("cl5").innerHTML="O";362 }else if(document.getElementById("cl6").textContent==""){363 document.getElementById("cl6").innerHTML="O";364 }else if(document.getElementById("cl7").textContent==""){365 document.getElementById("cl7").innerHTML="O";366 }else if(document.getElementById("cl8").textContent==""){367 document.getElementById("cl8").innerHTML="O";368 }else if(document.getElementById("cl9").textContent==""){369 document.getElementById("cl9").innerHTML="O";370 } 371 }else if(document.getElementById("cl7").textContent=="X" && document.getElementById("cl3").textContent=="X"){372 if(document.getElementById("cl5").textContent==""){373 document.getElementById("cl5").innerHTML="O";374 }else if (document.getElementById("cl1").textContent==""){375 document.getElementById("cl1").innerHTML="O";376 }else if(document.getElementById("cl2").textContent==""){377 document.getElementById("cl2").innerHTML="O";378 }else if(document.getElementById("cl4").textContent==""){379 document.getElementById("cl4").innerHTML="O";380 }else if(document.getElementById("cl5").textContent==""){381 document.getElementById("cl5").innerHTML="O";382 }else if(document.getElementById("cl6").textContent==""){383 document.getElementById("cl6").innerHTML="O";384 }else if(document.getElementById("cl7").textContent==""){385 document.getElementById("cl7").innerHTML="O";386 }else if(document.getElementById("cl8").textContent==""){387 document.getElementById("cl8").innerHTML="O";388 }else if(document.getElementById("cl9").textContent==""){389 document.getElementById("cl9").innerHTML="O";390 } 391 }else if(document.getElementById("cl5").textContent=="X" && document.getElementById("cl3").textContent=="X"){392 if(document.getElementById("cl7").textContent==""){393 document.getElementById("cl7").innerHTML="O";394 }else if (document.getElementById("cl1").textContent==""){395 document.getElementById("cl1").innerHTML="O";396 }else if(document.getElementById("cl2").textContent==""){397 document.getElementById("cl2").innerHTML="O";398 }else if(document.getElementById("cl4").textContent==""){399 document.getElementById("cl4").innerHTML="O";400 }else if(document.getElementById("cl5").textContent==""){401 document.getElementById("cl5").innerHTML="O";402 }else if(document.getElementById("cl6").textContent==""){403 document.getElementById("cl6").innerHTML="O";404 }else if(document.getElementById("cl7").textContent==""){405 document.getElementById("cl7").innerHTML="O";406 }else if(document.getElementById("cl8").textContent==""){407 document.getElementById("cl8").innerHTML="O";408 }else if(document.getElementById("cl9").textContent==""){409 document.getElementById("cl9").innerHTML="O";410 } 411 }else if (document.getElementById("cl1").textContent==""){412 document.getElementById("cl1").innerHTML="O";413 }else if(document.getElementById("cl2").textContent==""){414 document.getElementById("cl2").innerHTML="O";415 }else if(document.getElementById("cl4").textContent==""){416 document.getElementById("cl4").innerHTML="O";417 }else if(document.getElementById("cl5").textContent==""){418 document.getElementById("cl5").innerHTML="O";419 }else if(document.getElementById("cl6").textContent==""){420 document.getElementById("cl6").innerHTML="O";421 }else if(document.getElementById("cl7").textContent==""){422 document.getElementById("cl7").innerHTML="O";423 }else if(document.getElementById("cl8").textContent==""){424 document.getElementById("cl8").innerHTML="O";425 }else if(document.getElementById("cl9").textContent==""){426 document.getElementById("cl9").innerHTML="O";427 }428 } else {429 alert("try another squre");430 }431 }else{432 alert("Please try again");433 }434})435$('#cl4').click(function(){436if($('#result h2').text()==""){437if (document.getElementById("cl4").textContent==""){438 document.getElementById("cl4").innerHTML="X";439 if(document.getElementById("cl1").textContent=="X"){440 if(document.getElementById("cl7").textContent==""){441 document.getElementById("cl7").innerHTML="O";442 }else if (document.getElementById("cl1").textContent==""){443 document.getElementById("cl1").innerHTML="O";444 }else if(document.getElementById("cl2").textContent==""){445 document.getElementById("cl2").innerHTML="O";446 447 }else if(document.getElementById("cl3").textContent==""){448 document.getElementById("cl3").innerHTML="O";449 }else if(document.getElementById("cl5").textContent==""){450 document.getElementById("cl5").innerHTML="O";451 }else if(document.getElementById("cl6").textContent==""){452 document.getElementById("cl6").innerHTML="O";453 }else if(document.getElementById("cl7").textContent==""){454 document.getElementById("cl7").innerHTML="O";455 }else if(document.getElementById("cl8").textContent==""){456 document.getElementById("cl8").innerHTML="O";457 }else if(document.getElementById("cl9").textContent==""){458 document.getElementById("cl9").innerHTML="O";459 }460 }else if(document.getElementById("cl7").textContent=="X"){461 if(document.getElementById("cl1").textContent==""){462 document.getElementById("cl1").innerHTML="O";463 }else if (document.getElementById("cl1").textContent==""){464 document.getElementById("cl1").innerHTML="O";465 }else if(document.getElementById("cl2").textContent==""){466 document.getElementById("cl2").innerHTML="O";467 }else if(document.getElementById("cl3").textContent==""){468 document.getElementById("cl3").innerHTML="O";469 }else if(document.getElementById("cl5").textContent==""){470 document.getElementById("cl5").innerHTML="O";471 }else if(document.getElementById("cl6").textContent==""){472 document.getElementById("cl6").innerHTML="O";473 }else if(document.getElementById("cl7").textContent==""){474 document.getElementById("cl7").innerHTML="O";475 }else if(document.getElementById("cl8").textContent==""){476 document.getElementById("cl8").innerHTML="O";477 }else if(document.getElementById("cl9").textContent==""){478 document.getElementById("cl9").innerHTML="O";479 }480 }else if(document.getElementById("cl5").textContent=="X" && document.getElementById("cl4").textContent=="X"){481 if(document.getElementById("cl6").textContent==""){482 document.getElementById("cl6").innerHTML="O";483 }else if (document.getElementById("cl1").textContent==""){484 document.getElementById("cl1").innerHTML="O";485 }else if(document.getElementById("cl2").textContent==""){486 document.getElementById("cl2").innerHTML="O";487 }else if(document.getElementById("cl3").textContent==""){488 document.getElementById("cl3").innerHTML="O";489 }else if(document.getElementById("cl5").textContent==""){490 document.getElementById("cl5").innerHTML="O";491 }else if(document.getElementById("cl6").textContent==""){492 document.getElementById("cl6").innerHTML="O";493 }else if(document.getElementById("cl7").textContent==""){494 document.getElementById("cl7").innerHTML="O";495 }else if(document.getElementById("cl8").textContent==""){496 document.getElementById("cl8").innerHTML="O";497 }else if(document.getElementById("cl9").textContent==""){498 document.getElementById("cl9").innerHTML="O";499 }500 }else if(document.getElementById("cl6").textContent=="X" && document.getElementById("cl4").textContent=="X"){501 if(document.getElementById("cl5").textContent==""){502 document.getElementById("cl5").innerHTML="O";503 }else if (document.getElementById("cl1").textContent==""){504 document.getElementById("cl1").innerHTML="O";505 }else if(document.getElementById("cl2").textContent==""){506 document.getElementById("cl2").innerHTML="O";507 }else if(document.getElementById("cl3").textContent==""){508 document.getElementById("cl3").innerHTML="O";509 }else if(document.getElementById("cl5").textContent==""){510 document.getElementById("cl5").innerHTML="O";511 }else if(document.getElementById("cl6").textContent==""){512 document.getElementById("cl6").innerHTML="O";513 }else if(document.getElementById("cl7").textContent==""){514 document.getElementById("cl7").innerHTML="O";515 }else if(document.getElementById("cl8").textContent==""){516 document.getElementById("cl8").innerHTML="O";517 }else if(document.getElementById("cl9").textContent==""){518 document.getElementById("cl9").innerHTML="O";519 }520 }else if (document.getElementById("cl1").textContent==""){521 document.getElementById("cl1").innerHTML="O";522 }else if(document.getElementById("cl2").textContent==""){523 document.getElementById("cl2").innerHTML="O";524 }else if(document.getElementById("cl3").textContent==""){525 document.getElementById("cl3").innerHTML="O";526 }else if(document.getElementById("cl5").textContent==""){527 document.getElementById("cl5").innerHTML="O";528 }else if(document.getElementById("cl6").textContent==""){529 document.getElementById("cl6").innerHTML="O";530 }else if(document.getElementById("cl7").textContent==""){531 document.getElementById("cl7").innerHTML="O";532 }else if(document.getElementById("cl8").textContent==""){533 document.getElementById("cl8").innerHTML="O";534 }else if(document.getElementById("cl9").textContent==""){535 document.getElementById("cl9").innerHTML="O";536 }537 } else {538 alert("try another squre");539 } 540 }else{541 alert("Please try again");542 }543})544$('#cl5').click(function(){545if($('#result h2').text()==""){546if (document.getElementById("cl5").textContent==""){547 document.getElementById("cl5").innerHTML="X";548 if(document.getElementById("cl1").textContent=="X"){549 if(document.getElementById("cl9").textContent==""){550 document.getElementById("cl9").innerHTML="O";551 }552 }else if(document.getElementById("cl2").textContent=="X"){553 if(document.getElementById("cl8").textContent==""){554 document.getElementById("cl8").innerHTML="O";555 }556 }else if(document.getElementById("cl3").textContent=="X"){557 if(document.getElementById("cl7").textContent==""){558 document.getElementById("cl7").innerHTML="O";559 }560 }else if(document.getElementById("cl4").textContent=="X"){561 if(document.getElementById("cl6").textContent==""){562 document.getElementById("cl6").innerHTML="O";563 }564 }else if(document.getElementById("cl6").textContent=="X"){565 if(document.getElementById("cl4").textContent==""){566 document.getElementById("cl4").innerHTML="O";567 }568 }else if(document.getElementById("cl7").textContent=="X"){569 if(document.getElementById("cl3").textContent==""){570 document.getElementById("cl3").innerHTML="O";571 }572 }else if(document.getElementById("cl8").textContent=="X"){573 if(document.getElementById("cl2").textContent==""){574 document.getElementById("cl2").innerHTML="O";575 }576 }else if(document.getElementById("cl9").textContent=="X"){577 if(document.getElementById("cl1").textContent==""){578 document.getElementById("cl1").innerHTML="O";579 }580 }else if (document.getElementById("cl1").textContent==""){581 document.getElementById("cl1").innerHTML="O";582 }else if(document.getElementById("cl2").textContent==""){583 document.getElementById("cl2").innerHTML="O";584 }else if(document.getElementById("cl3").textContent==""){585 document.getElementById("cl3").innerHTML="O";586 }else if(document.getElementById("cl4").textContent==""){587 document.getElementById("cl4").innerHTML="O";588 }else if(document.getElementById("cl6").textContent==""){589 document.getElementById("cl6").innerHTML="O";590 }else if(document.getElementById("cl7").textContent==""){591 document.getElementById("cl7").innerHTML="O";592 }else if(document.getElementById("cl8").textContent==""){593 document.getElementById("cl8").innerHTML="O";594 }else if(document.getElementById("cl9").textContent==""){595 document.getElementById("cl9").innerHTML="O";596 }597 } else {598 alert("try another squre");599 }600 }else{601 alert("Please try again");602 }603})604$('#cl6').click(function(){605if($('#result h2').text()==""){606if (document.getElementById("cl6").textContent==""){607 document.getElementById("cl6").innerHTML="X";608 if(document.getElementById("cl3").textContent=="X"){609 if(document.getElementById("cl9").textContent==""){610 document.getElementById("cl9").innerHTML="O";611 }else if (document.getElementById("cl1").textContent==""){612 document.getElementById("cl1").innerHTML="O";613 }else if(document.getElementById("cl2").textContent==""){614 document.getElementById("cl2").innerHTML="O";615 }else if(document.getElementById("cl3").textContent==""){616 document.getElementById("cl3").innerHTML="O";617 }else if(document.getElementById("cl4").textContent==""){618 document.getElementById("cl4").innerHTML="O";619 }else if(document.getElementById("cl5").textContent==""){620 document.getElementById("cl5").innerHTML="O";621 }else if(document.getElementById("cl7").textContent==""){622 document.getElementById("cl7").innerHTML="O";623 }else if(document.getElementById("cl8").textContent==""){624 document.getElementById("cl8").innerHTML="O";625 }else if(document.getElementById("cl9").textContent==""){626 document.getElementById("cl9").innerHTML="O";627 }628 }else if(document.getElementById("cl9").textContent=="X"){629 if(document.getElementById("cl3").textContent==""){630 document.getElementById("cl3").innerHTML="O";631 }else if (document.getElementById("cl1").textContent==""){632 document.getElementById("cl1").innerHTML="O";633 }else if(document.getElementById("cl2").textContent==""){634 document.getElementById("cl2").innerHTML="O";635 }else if(document.getElementById("cl3").textContent==""){636 document.getElementById("cl3").innerHTML="O";637 }else if(document.getElementById("cl4").textContent==""){638 document.getElementById("cl4").innerHTML="O";639 }else if(document.getElementById("cl5").textContent==""){640 document.getElementById("cl5").innerHTML="O";641 }else if(document.getElementById("cl7").textContent==""){642 document.getElementById("cl7").innerHTML="O";643 }else if(document.getElementById("cl8").textContent==""){644 document.getElementById("cl8").innerHTML="O";645 }else if(document.getElementById("cl9").textContent==""){646 document.getElementById("cl9").innerHTML="O";647 }648 }else if(document.getElementById("cl5").textContent=="X" && document.getElementById("cl6").textContent=="X"){649 if(document.getElementById("cl4").textContent==""){650 document.getElementById("cl4").innerHTML="O";651 }else if (document.getElementById("cl1").textContent==""){652 document.getElementById("cl1").innerHTML="O";653 }else if(document.getElementById("cl2").textContent==""){654 document.getElementById("cl2").innerHTML="O";655 656 }else if(document.getElementById("cl3").textContent==""){657 document.getElementById("cl3").innerHTML="O";658 }else if(document.getElementById("cl4").textContent==""){659 document.getElementById("cl4").innerHTML="O";660 }else if(document.getElementById("cl5").textContent==""){661 document.getElementById("cl5").innerHTML="O";662 }else if(document.getElementById("cl7").textContent==""){663 document.getElementById("cl7").innerHTML="O";664 665 }else if(document.getElementById("cl8").textContent==""){666 document.getElementById("cl8").innerHTML="O";667 }else if(document.getElementById("cl9").textContent==""){668 document.getElementById("cl9").innerHTML="O";669 }670 }else if(document.getElementById("cl4").textContent=="X" && document.getElementById("cl6").textContent=="X"){671 if(document.getElementById("cl5").textContent==""){672 document.getElementById("cl5").innerHTML="O";673 }else if (document.getElementById("cl1").textContent==""){674 document.getElementById("cl1").innerHTML="O";675 }else if(document.getElementById("cl2").textContent==""){676 document.getElementById("cl2").innerHTML="O";677 }else if(document.getElementById("cl3").textContent==""){678 document.getElementById("cl3").innerHTML="O";679 }else if(document.getElementById("cl4").textContent==""){680 document.getElementById("cl4").innerHTML="O";681 }else if(document.getElementById("cl5").textContent==""){682 document.getElementById("cl5").innerHTML="O";683 }else if(document.getElementById("cl7").textContent==""){684 document.getElementById("cl7").innerHTML="O";685 }else if(document.getElementById("cl8").textContent==""){686 document.getElementById("cl8").innerHTML="O";687 }else if(document.getElementById("cl9").textContent==""){688 document.getElementById("cl9").innerHTML="O";689 }690 }else if (document.getElementById("cl1").textContent==""){691 document.getElementById("cl1").innerHTML="O";692 }else if(document.getElementById("cl2").textContent==""){693 document.getElementById("cl2").innerHTML="O";694 }else if(document.getElementById("cl3").textContent==""){695 document.getElementById("cl3").innerHTML="O";696 }else if(document.getElementById("cl4").textContent==""){697 document.getElementById("cl4").innerHTML="O";698 }else if(document.getElementById("cl5").textContent==""){699 document.getElementById("cl5").innerHTML="O";700 }else if(document.getElementById("cl7").textContent==""){701 document.getElementById("cl7").innerHTML="O";702 }else if(document.getElementById("cl8").textContent==""){703 document.getElementById("cl8").innerHTML="O";704 }else if(document.getElementById("cl9").textContent==""){705 document.getElementById("cl9").innerHTML="O";706 }707 } else {708 alert("try another squre");709 }710 }else{711 alert("Please try again");712 }713})714$('#cl7').click(function(){715if($('#result h2').text()==""){716if (document.getElementById("cl7").textContent==""){717 document.getElementById("cl7").innerHTML="X";718 if(document.getElementById("cl4").textContent=="X"){719 if(document.getElementById("cl1").textContent==""){720 document.getElementById("cl1").innerHTML="O";721 }else if (document.getElementById("cl1").textContent==""){722 document.getElementById("cl1").innerHTML="O";723 }else if(document.getElementById("cl2").textContent==""){724 document.getElementById("cl2").innerHTML="O";725 }else if(document.getElementById("cl3").textContent==""){726 document.getElementById("cl3").innerHTML="O";727 }else if(document.getElementById("cl4").textContent==""){728 document.getElementById("cl5").innerHTML="O";729 }else if(document.getElementById("cl5").textContent==""){730 document.getElementById("cl5").innerHTML="O";731 }else if(document.getElementById("cl6").textContent==""){732 document.getElementById("cl6").innerHTML="O";733 }else if(document.getElementById("cl8").textContent==""){734 document.getElementById("cl8").innerHTML="O";735 }else if(document.getElementById("cl9").textContent==""){736 document.getElementById("cl9").innerHTML="O";737 }738 }else if(document.getElementById("cl8").textContent=="X"){739 if(document.getElementById("cl9").textContent==""){740 document.getElementById("cl9").innerHTML="O";741 }else if (document.getElementById("cl1").textContent==""){742 document.getElementById("cl1").innerHTML="O";743 }else if(document.getElementById("cl2").textContent==""){744 document.getElementById("cl2").innerHTML="O";745 }else if(document.getElementById("cl3").textContent==""){746 document.getElementById("cl3").innerHTML="O";747 }else if(document.getElementById("cl4").textContent==""){748 document.getElementById("cl5").innerHTML="O";749 }else if(document.getElementById("cl5").textContent==""){750 document.getElementById("cl5").innerHTML="O";751 }else if(document.getElementById("cl6").textContent==""){752 document.getElementById("cl6").innerHTML="O";753 }else if(document.getElementById("cl8").textContent==""){754 document.getElementById("cl8").innerHTML="O";755 }else if(document.getElementById("cl9").textContent==""){756 document.getElementById("cl9").innerHTML="O";757 }758 }else if(document.getElementById("cl7").textContent=="X" && document.getElementById("cl1").textContent=="X"){759 if(document.getElementById("cl4").textContent==""){760 document.getElementById("cl4").innerHTML="O";761 }else if (document.getElementById("cl1").textContent==""){762 document.getElementById("cl1").innerHTML="O";763 }else if(document.getElementById("cl2").textContent==""){764 document.getElementById("cl2").innerHTML="O";765 }else if(document.getElementById("cl3").textContent==""){766 document.getElementById("cl3").innerHTML="O";767 }else if(document.getElementById("cl4").textContent==""){768 document.getElementById("cl5").innerHTML="O";769 }else if(document.getElementById("cl5").textContent==""){770 document.getElementById("cl5").innerHTML="O";771 }else if(document.getElementById("cl6").textContent==""){772 document.getElementById("cl6").innerHTML="O";773 }else if(document.getElementById("cl8").textContent==""){774 document.getElementById("cl8").innerHTML="O";775 }else if(document.getElementById("cl9").textContent==""){776 document.getElementById("cl9").innerHTML="O";777 }778 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl7").textContent=="X"){779 if(document.getElementById("cl8").textContent==""){780 document.getElementById("cl8").innerHTML="O";781 }else if (document.getElementById("cl1").textContent==""){782 document.getElementById("cl1").innerHTML="O";783 }else if(document.getElementById("cl2").textContent==""){784 document.getElementById("cl2").innerHTML="O";785 }else if(document.getElementById("cl3").textContent==""){786 document.getElementById("cl3").innerHTML="O";787 }else if(document.getElementById("cl4").textContent==""){788 document.getElementById("cl5").innerHTML="O";789 }else if(document.getElementById("cl5").textContent==""){790 document.getElementById("cl5").innerHTML="O";791 }else if(document.getElementById("cl6").textContent==""){792 document.getElementById("cl6").innerHTML="O";793 }else if(document.getElementById("cl8").textContent==""){794 document.getElementById("cl8").innerHTML="O";795 }else if(document.getElementById("cl9").textContent==""){796 document.getElementById("cl9").innerHTML="O";797 } 798 }else if(document.getElementById("cl7").textContent=="X" && document.getElementById("cl3").textContent=="X"){799 if(document.getElementById("cl5").textContent==""){800 document.getElementById("cl5").innerHTML="O";801 } 802 }else if(document.getElementById("cl7").textContent=="X" && document.getElementById("cl5").textContent=="X"){803 if(document.getElementById("cl3").textContent==""){804 document.getElementById("cl3").innerHTML="O";805 }else if (document.getElementById("cl1").textContent==""){806 document.getElementById("cl1").innerHTML="O";807 }else if(document.getElementById("cl2").textContent==""){808 document.getElementById("cl2").innerHTML="O";809 }else if(document.getElementById("cl3").textContent==""){810 document.getElementById("cl3").innerHTML="O";811 }else if(document.getElementById("cl4").textContent==""){812 document.getElementById("cl5").innerHTML="O";813 }else if(document.getElementById("cl5").textContent==""){814 document.getElementById("cl5").innerHTML="O";815 }else if(document.getElementById("cl6").textContent==""){816 document.getElementById("cl6").innerHTML="O";817 }else if(document.getElementById("cl8").textContent==""){818 document.getElementById("cl8").innerHTML="O";819 }else if(document.getElementById("cl9").textContent==""){820 document.getElementById("cl9").innerHTML="O";821 } 822 }else if (document.getElementById("cl1").textContent==""){823 document.getElementById("cl1").innerHTML="O";824 }else if(document.getElementById("cl2").textContent==""){825 document.getElementById("cl2").innerHTML="O";826 }else if(document.getElementById("cl3").textContent==""){827 document.getElementById("cl3").innerHTML="O";828 }else if(document.getElementById("cl4").textContent==""){829 document.getElementById("cl5").innerHTML="O";830 }else if(document.getElementById("cl5").textContent==""){831 document.getElementById("cl5").innerHTML="O";832 }else if(document.getElementById("cl6").textContent==""){833 document.getElementById("cl6").innerHTML="O";834 }else if(document.getElementById("cl8").textContent==""){835 document.getElementById("cl8").innerHTML="O";836 }else if(document.getElementById("cl9").textContent==""){837 document.getElementById("cl9").innerHTML="O";838 }839 } else {840 alert("try another squre");841 } 842 }else{843 alert("Please try again");844 }845 846})847$('#cl8').click(function(){848if($('#result h2').text()==""){849if (document.getElementById("cl8").textContent==""){850 document.getElementById("cl8").innerHTML="X";851 if(document.getElementById("cl7").textContent=="X"){852 if(document.getElementById("cl9").textContent==""){853 document.getElementById("cl9").innerHTML="O";854 }else if (document.getElementById("cl1").textContent==""){855 document.getElementById("cl1").innerHTML="O";856 }else if(document.getElementById("cl2").textContent==""){857 document.getElementById("cl2").innerHTML="O";858 }else if(document.getElementById("cl3").textContent==""){859 document.getElementById("cl3").innerHTML="O";860 }else if(document.getElementById("cl4").textContent==""){861 document.getElementById("cl4").innerHTML="O";862 }else if(document.getElementById("cl5").textContent==""){863 document.getElementById("cl5").innerHTML="O";864 }else if(document.getElementById("cl6").textContent==""){865 document.getElementById("cl6").innerHTML="O";866 }else if(document.getElementById("cl7").textContent==""){867 document.getElementById("cl7").innerHTML="O";868 }else if(document.getElementById("cl9").textContent==""){869 document.getElementById("cl9").innerHTML="O";870 }871 }else if(document.getElementById("cl9").textContent=="X"){872 if(document.getElementById("cl7").textContent==""){873 document.getElementById("cl7").innerHTML="O";874 }else if (document.getElementById("cl1").textContent==""){875 document.getElementById("cl1").innerHTML="O";876 }else if(document.getElementById("cl2").textContent==""){877 document.getElementById("cl2").innerHTML="O";878 }else if(document.getElementById("cl3").textContent==""){879 document.getElementById("cl3").innerHTML="O";880 }else if(document.getElementById("cl4").textContent==""){881 document.getElementById("cl4").innerHTML="O";882 }else if(document.getElementById("cl5").textContent==""){883 document.getElementById("cl5").innerHTML="O";884 }else if(document.getElementById("cl6").textContent==""){885 document.getElementById("cl6").innerHTML="O";886 }else if(document.getElementById("cl7").textContent==""){887 document.getElementById("cl7").innerHTML="O";888 }else if(document.getElementById("cl9").textContent==""){889 document.getElementById("cl9").innerHTML="O";890 }891 }else if(document.getElementById("cl8").textContent=="X" && document.getElementById("cl2").textContent=="X"){892 if(document.getElementById("cl5").textContent==""){893 document.getElementById("cl5").innerHTML="O";894 }else if (document.getElementById("cl1").textContent==""){895 document.getElementById("cl1").innerHTML="O";896 }else if(document.getElementById("cl2").textContent==""){897 document.getElementById("cl2").innerHTML="O";898 }else if(document.getElementById("cl3").textContent==""){899 document.getElementById("cl3").innerHTML="O";900 }else if(document.getElementById("cl4").textContent==""){901 document.getElementById("cl4").innerHTML="O";902 }else if(document.getElementById("cl5").textContent==""){903 document.getElementById("cl5").innerHTML="O";904 }else if(document.getElementById("cl6").textContent==""){905 document.getElementById("cl6").innerHTML="O";906 }else if(document.getElementById("cl7").textContent==""){907 document.getElementById("cl7").innerHTML="O";908 }else if(document.getElementById("cl9").textContent==""){909 document.getElementById("cl9").innerHTML="O";910 }911 }else if(document.getElementById("cl8").textContent=="X" && document.getElementById("cl5").textContent=="X"){912 if(document.getElementById("cl2").textContent==""){913 document.getElementById("cl2").innerHTML="O";914 }else if (document.getElementById("cl1").textContent==""){915 document.getElementById("cl1").innerHTML="O";916 }else if(document.getElementById("cl2").textContent==""){917 document.getElementById("cl2").innerHTML="O";918 }else if(document.getElementById("cl3").textContent==""){919 document.getElementById("cl3").innerHTML="O";920 }else if(document.getElementById("cl4").textContent==""){921 document.getElementById("cl4").innerHTML="O";922 }else if(document.getElementById("cl5").textContent==""){923 document.getElementById("cl5").innerHTML="O";924 }else if(document.getElementById("cl6").textContent==""){925 document.getElementById("cl6").innerHTML="O";926 }else if(document.getElementById("cl7").textContent==""){927 document.getElementById("cl7").innerHTML="O";928 }else if(document.getElementById("cl9").textContent==""){929 document.getElementById("cl9").innerHTML="O";930 }931 }else if (document.getElementById("cl1").textContent==""){932 document.getElementById("cl1").innerHTML="O";933 }else if(document.getElementById("cl2").textContent==""){934 document.getElementById("cl2").innerHTML="O";935 }else if(document.getElementById("cl3").textContent==""){936 document.getElementById("cl3").innerHTML="O";937 }else if(document.getElementById("cl4").textContent==""){938 document.getElementById("cl4").innerHTML="O";939 }else if(document.getElementById("cl5").textContent==""){940 document.getElementById("cl5").innerHTML="O";941 }else if(document.getElementById("cl6").textContent==""){942 document.getElementById("cl6").innerHTML="O";943 }else if(document.getElementById("cl7").textContent==""){944 document.getElementById("cl7").innerHTML="O";945 }else if(document.getElementById("cl9").textContent==""){946 document.getElementById("cl9").innerHTML="O";947 }948 } else {949 alert("try another squre");950 }951 }else{952 alert("Please try again");953 }954})955$('#cl9').click(function(){956if($('#result h2').text()==""){957if (document.getElementById("cl9").textContent==""){958 document.getElementById("cl9").innerHTML="X";959 if(document.getElementById("cl6").textContent=="X"){960 if(document.getElementById("cl3").textContent==""){961 document.getElementById("cl3").innerHTML="O";962 }else if (document.getElementById("cl5").textContent==""){963 document.getElementById("cl5").innerHTML="O";964 }else if(document.getElementById("cl2").textContent==""){965 document.getElementById("cl2").innerHTML="O";966 }else if(document.getElementById("cl3").textContent==""){967 document.getElementById("cl3").innerHTML="O";968 }else if(document.getElementById("cl4").textContent==""){969 document.getElementById("cl4").innerHTML="O";970 }else if(document.getElementById("cl1").textContent==""){971 document.getElementById("cl1").innerHTML="O";972 }else if(document.getElementById("cl6").textContent==""){973 document.getElementById("cl6").innerHTML="O";974 }else if(document.getElementById("cl7").textContent==""){975 document.getElementById("cl7").innerHTML="O";976 }else if(document.getElementById("cl8").textContent==""){977 document.getElementById("cl8").innerHTML="O";978 }979 }else if(document.getElementById("cl8").textContent=="X"){980 if(document.getElementById("cl7").textContent==""){981 document.getElementById("cl7").innerHTML="O";982 }else if (document.getElementById("cl5").textContent==""){983 document.getElementById("cl5").innerHTML="O";984 }else if(document.getElementById("cl2").textContent==""){985 document.getElementById("cl2").innerHTML="O";986 }else if(document.getElementById("cl3").textContent==""){987 document.getElementById("cl3").innerHTML="O";988 }else if(document.getElementById("cl4").textContent==""){989 document.getElementById("cl4").innerHTML="O";990 }else if(document.getElementById("cl1").textContent==""){991 document.getElementById("cl1").innerHTML="O";992 }else if(document.getElementById("cl6").textContent==""){993 document.getElementById("cl6").innerHTML="O";994 995 }else if(document.getElementById("cl7").textContent==""){996 document.getElementById("cl7").innerHTML="O";997 }else if(document.getElementById("cl8").textContent==""){998 document.getElementById("cl8").innerHTML="O";999 }1000 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl3").textContent=="X"){1001 if(document.getElementById("cl6").textContent==""){1002 document.getElementById("cl6").innerHTML="O";1003 }else if (document.getElementById("cl5").textContent==""){1004 document.getElementById("cl5").innerHTML="O";1005 }else if(document.getElementById("cl2").textContent==""){1006 document.getElementById("cl2").innerHTML="O";1007 }else if(document.getElementById("cl3").textContent==""){1008 document.getElementById("cl3").innerHTML="O";1009 }else if(document.getElementById("cl4").textContent==""){1010 document.getElementById("cl4").innerHTML="O";1011 }else if(document.getElementById("cl1").textContent==""){1012 document.getElementById("cl1").innerHTML="O";1013 }else if(document.getElementById("cl6").textContent==""){1014 document.getElementById("cl6").innerHTML="O";1015 }else if(document.getElementById("cl7").textContent==""){1016 document.getElementById("cl7").innerHTML="O";1017 }else if(document.getElementById("cl8").textContent==""){1018 document.getElementById("cl8").innerHTML="O";1019 }1020 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl7").textContent=="X"){1021 if(document.getElementById("cl8").textContent==""){1022 document.getElementById("cl8").innerHTML="O";1023 }else if (document.getElementById("cl5").textContent==""){1024 document.getElementById("cl5").innerHTML="O";1025 }else if(document.getElementById("cl2").textContent==""){1026 document.getElementById("cl2").innerHTML="O";1027 }else if(document.getElementById("cl3").textContent==""){1028 document.getElementById("cl3").innerHTML="O";1029 }else if(document.getElementById("cl4").textContent==""){1030 document.getElementById("cl4").innerHTML="O";1031 }else if(document.getElementById("cl1").textContent==""){1032 document.getElementById("cl1").innerHTML="O";1033 }else if(document.getElementById("cl6").textContent==""){1034 document.getElementById("cl6").innerHTML="O";1035 }else if(document.getElementById("cl7").textContent==""){1036 document.getElementById("cl7").innerHTML="O";1037 }else if(document.getElementById("cl8").textContent==""){1038 document.getElementById("cl8").innerHTML="O";1039 } 1040 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl1").textContent=="X"){1041 if(document.getElementById("cl5").textContent==""){1042 document.getElementById("cl5").innerHTML="O";1043 }else if (document.getElementById("cl5").textContent==""){1044 document.getElementById("cl5").innerHTML="O";1045 }else if(document.getElementById("cl2").textContent==""){1046 document.getElementById("cl2").innerHTML="O";1047 }else if(document.getElementById("cl3").textContent==""){1048 document.getElementById("cl3").innerHTML="O";1049 }else if(document.getElementById("cl4").textContent==""){1050 document.getElementById("cl4").innerHTML="O";1051 1052 }else if(document.getElementById("cl1").textContent==""){1053 document.getElementById("cl1").innerHTML="O";1054 }else if(document.getElementById("cl6").textContent==""){1055 document.getElementById("cl6").innerHTML="O";1056 1057 }else if(document.getElementById("cl7").textContent==""){1058 document.getElementById("cl7").innerHTML="O";1059 1060 }else if(document.getElementById("cl8").textContent==""){1061 document.getElementById("cl8").innerHTML="O";1062 } 1063 }else if(document.getElementById("cl9").textContent=="X" && document.getElementById("cl5").textContent=="X"){1064 if(document.getElementById("cl1").textContent==""){1065 document.getElementById("cl1").innerHTML="O";1066 }else if (document.getElementById("cl5").textContent==""){1067 document.getElementById("cl5").innerHTML="O";1068 }else if(document.getElementById("cl2").textContent==""){1069 document.getElementById("cl2").innerHTML="O";1070 }else if(document.getElementById("cl3").textContent==""){1071 document.getElementById("cl3").innerHTML="O";1072 }else if(document.getElementById("cl4").textContent==""){1073 document.getElementById("cl4").innerHTML="O";1074 }else if(document.getElementById("cl1").textContent==""){1075 document.getElementById("cl1").innerHTML="O";1076 }else if(document.getElementById("cl6").textContent==""){1077 document.getElementById("cl6").innerHTML="O";1078 }else if(document.getElementById("cl7").textContent==""){1079 document.getElementById("cl7").innerHTML="O";1080 }else if(document.getElementById("cl8").textContent==""){1081 document.getElementById("cl8").innerHTML="O";1082 } 1083 }else if (document.getElementById("cl5").textContent==""){1084 document.getElementById("cl5").innerHTML="O";1085 }else if(document.getElementById("cl2").textContent==""){1086 document.getElementById("cl2").innerHTML="O";1087 }else if(document.getElementById("cl3").textContent==""){1088 document.getElementById("cl3").innerHTML="O";1089 }else if(document.getElementById("cl4").textContent==""){1090 document.getElementById("cl4").innerHTML="O";1091 }else if(document.getElementById("cl1").textContent==""){1092 document.getElementById("cl1").innerHTML="O";1093 }else if(document.getElementById("cl6").textContent==""){1094 document.getElementById("cl6").innerHTML="O";1095 }else if(document.getElementById("cl7").textContent==""){1096 document.getElementById("cl7").innerHTML="O";1097 }else if(document.getElementById("cl8").textContent==""){1098 document.getElementById("cl8").innerHTML="O";1099 }1100 } else {1101 alert("try another squre");1102 } 1103 }else{1104 alert("Please try again");1105 }1106 1107})1108 $('#cl1').click(function () {1109 var s= $('#cl1').text();1110 var s2= $('#cl2').text();1111 var s3= $('#cl3').text();1112 var s4= $('#cl4').text();1113 var s5= $('#cl5').text();1114 var s6= $('#cl6').text();1115 var s7= $('#cl7').text();1116 var s8= $('#cl8').text();1117 var s9= $('#cl9').text();1118 $.ajax({1119 url: 'receive',1120 type: 'post',1121 dataType: 'html',1122 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1123 success : function(data) {1124 $('#result').html(data);1125 },1126 });1127 });1128 $('#cl2').click(function () {1129 var s= $('#cl1').text();1130 var s2= $('#cl2').text();1131 var s3= $('#cl3').text();1132 var s4= $('#cl4').text();1133 var s5= $('#cl5').text();1134 var s6= $('#cl6').text();1135 var s7= $('#cl7').text();1136 var s8= $('#cl8').text();1137 var s9= $('#cl9').text();1138 $.ajax({1139 url: 'receive',1140 type: 'post',1141 dataType: 'html',1142 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1143 success : function(data) {1144 $('#result').html(data); 1145 },1146 });1147 });1148 $('#cl3').click(function () {1149 var s= $('#cl1').text();1150 var s2= $('#cl2').text();1151 var s3= $('#cl3').text();1152 var s4= $('#cl4').text();1153 var s5= $('#cl5').text();1154 var s6= $('#cl6').text();1155 var s7= $('#cl7').text();1156 var s8= $('#cl8').text();1157 var s9= $('#cl9').text();1158 $.ajax({1159 url: 'receive',1160 type: 'post',1161 dataType: 'html',1162 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1163 success : function(data) {1164 $('#result').html(data); 1165 },1166 });1167 });1168 $('#cl4').click(function () {1169 var s= $('#cl1').text();1170 var s2= $('#cl2').text();1171 var s3= $('#cl3').text();1172 var s4= $('#cl4').text();1173 var s5= $('#cl5').text();1174 var s6= $('#cl6').text();1175 var s7= $('#cl7').text();1176 var s8= $('#cl8').text();1177 var s9= $('#cl9').text();1178 $.ajax({1179 url: 'receive',1180 type: 'post',1181 dataType: 'html',1182 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1183 success : function(data) {1184 $('#result').html(data);1185 },1186 });1187 });1188 $('#cl5').click(function () {1189 var s= $('#cl1').text();1190 var s2= $('#cl2').text();1191 var s3= $('#cl3').text();1192 var s4= $('#cl4').text();1193 var s5= $('#cl5').text();1194 var s6= $('#cl6').text();1195 var s7= $('#cl7').text();1196 var s8= $('#cl8').text();1197 var s9= $('#cl9').text();1198 $.ajax({1199 url: 'receive',1200 type: 'post',1201 dataType: 'html',1202 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1203 success : function(data) {1204 $('#result').html(data);1205 },1206 });1207 });1208 $('#cl6').click(function () {1209 var s= $('#cl1').text();1210 var s2= $('#cl2').text();1211 var s3= $('#cl3').text();1212 var s4= $('#cl4').text();1213 var s5= $('#cl5').text();1214 var s6= $('#cl6').text();1215 var s7= $('#cl7').text();1216 var s8= $('#cl8').text();1217 var s9= $('#cl9').text();1218 $.ajax({1219 url: 'receive',1220 type: 'post',1221 dataType: 'html',1222 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1223 success : function(data) {1224 $('#result').html(data);1225 },1226 });1227 });1228 $('#cl7').click(function () {1229 var s= $('#cl1').text();1230 var s2= $('#cl2').text();1231 var s3= $('#cl3').text();1232 var s4= $('#cl4').text();1233 var s5= $('#cl5').text();1234 var s6= $('#cl6').text();1235 var s7= $('#cl7').text();1236 var s8= $('#cl8').text();1237 var s9= $('#cl9').text();1238 $.ajax({1239 url: 'receive',1240 type: 'post',1241 dataType: 'html',1242 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1243 success : function(data) {1244 $('#result').html(data);1245 },1246 });1247 });1248 $('#cl8').click(function () {1249 var s= $('#cl1').text();1250 var s2= $('#cl2').text();1251 var s3= $('#cl3').text();1252 var s4= $('#cl4').text();1253 var s5= $('#cl5').text();1254 var s6= $('#cl6').text();1255 var s7= $('#cl7').text();1256 var s8= $('#cl8').text();1257 var s9= $('#cl9').text();1258 $.ajax({1259 url: 'receive',1260 type: 'post',1261 dataType: 'html',1262 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1263 success : function(data) {1264 $('#result').html(data);1265 },1266 });1267 });1268 $('#cl9').click(function () {1269 var s= $('#cl1').text();1270 var s2= $('#cl2').text();1271 var s3= $('#cl3').text();1272 var s4= $('#cl4').text();1273 var s5= $('#cl5').text();1274 var s6= $('#cl6').text();1275 var s7= $('#cl7').text();1276 var s8= $('#cl8').text();1277 var s9= $('#cl9').text();1278 $.ajax({1279 url: 'receive',1280 type: 'post',1281 dataType: 'html',1282 data : { cf1:s,cf2:s2,cf3:s3,cf4:s4,cf5:s5,cf6:s6,cf7:s7,cf8:s8,cf9:s9},1283 success : function(data) {1284 $('#result').html(data);1285 },1286 });1287 });1288</script>`1289 w.Write([]byte(fmt.Sprintf(html)))1290}1291func receiveAjax(w http.ResponseWriter, r *http.Request) {1292 if r.Method == "POST" {1293 data1 := r.FormValue("cf1")1294 data2 := r.FormValue("cf2")1295 data3 := r.FormValue("cf3")1296 data4 := r.FormValue("cf4")1297 data5 := r.FormValue("cf5")1298 data6 := r.FormValue("cf6")1299 //1300 data7 := r.FormValue("cf7")1301 data8 := r.FormValue("cf8")1302 data9 := r.FormValue("cf9")1303 if(data1==data2 && data3==data1 ){1304 if(data1!=""){1305 if (data1=="X") {1306 fmt.Println("You Win")1307 w.Write([]byte("<h2>You Win<h2>"))1308 }else {1309 fmt.Println("You Lose")1310 w.Write([]byte("<h2>You Lost<h2>"))1311 }1312 fmt.Println("1")1313 }1314 }else if(data4==data5 && data4==data6 ){1315 if(data4!=""){1316 if(data4=="X"){1317 fmt.Println("You Win")1318 w.Write([]byte("<h2>You Win<h2>"))1319 }else {1320 fmt.Println("You Lose")1321 w.Write([]byte("<h2>You Lose<h2>"))1322 }1323 fmt.Println("2")1324 }1325 }else if (data7==data8 && data8==data9 ) {1326 if(data7!=""){1327 if(data7=="X"){1328 fmt.Println("You Win")1329 w.Write([]byte("<h2>You Win<h2>"))1330 }else {1331 fmt.Println("You Lose")1332 w.Write([]byte("<h2>You Lose<h2>"))1333 }1334 fmt.Println("3")1335 }1336 }else if(data1==data4 && data4==data7 ){1337 if(data4!=""){1338 if (data4=="X") {1339 fmt.Println("You win")1340 w.Write([]byte("<h2>You Win<h2>"))1341 }else {1342 fmt.Println("You Lose")1343 w.Write([]byte("<h2>You Lose<h2>"))1344 }1345 fmt.Println("4")1346 }1347 }else if(data2==data5 && data2==data8 ){1348 if(data2!=""){1349 if(data2=="X"){1350 fmt.Println("You Win")1351 w.Write([]byte("<h2>You Win<h2>"))1352 }else {1353 fmt.Println("You Lose")1354 w.Write([]byte("<h2>You Lose<h2>"))1355 }1356 fmt.Println("5")1357 }1358 }else if(data3==data6 && data6==data9 ){1359 if(data3!=""){1360 if(data3=="X"){1361 fmt.Println("You Win")1362 w.Write([]byte("<h2>You Win<h2>"))1363 }else {1364 fmt.Println("You Lose")1365 w.Write([]byte("<h2>You Lose<h2>"))1366 }1367 fmt.Println("6")1368 }1369 }else if(data7==data5 && data7==data3 ){1370 if(data7!=""){1371 if(data7=="X"){1372 fmt.Println("You Win")1373 w.Write([]byte("<h2>You Win<h2>"))1374 }else {1375 fmt.Println("You Lose")1376 w.Write([]byte("<h2>You Lose<h2>"))1377 }1378 fmt.Println("7")1379 }1380 }else if(data1==data5 && data9==data1 ){1381 if(data5!=""){1382 if (data5=="X") {1383 fmt.Println("You Win")1384 w.Write([]byte("<h2>You Win<h2>"))1385 }else {1386 fmt.Println("You Lose")1387 w.Write([]byte("<h2>You Lose<h2>"))1388 }1389 fmt.Println("8")1390 }1391 }else if (data1!="" && data2!="" && data3!="" && data4!="" && data5!="" && data6!="" && data7!="" && data8!="" && data9!="") {1392 fmt.Println("Draw")1393 w.Write([]byte("<h2>Draw<h2>"))1394 }1395 }1396}1397func main() {1398 // http.Handler1399 mux := http.NewServeMux()1400 mux.HandleFunc("/", Home)1401 mux.HandleFunc("/receive", receiveAjax)1402 http.ListenAndServe(":8080", mux)1403}...
main.go
Source:main.go
1package main2import (3 "fmt"4 "github.com/gin-gonic/gin"5 "html/template"6 "io"7 "log"8 "net/http"9 "os"10 "rewan/controllers"11 "rewan/controllers/routines"12 "rewan/models"13 "rewan/models/memorygame"14 "rewan/models/persistence"15 "strconv"16)17/** AUTHOR : Erwan Le Bihan **/18/** The source code is open for anyone to see it. **/19//Functions we can use in templates20var funcMap = template.FuncMap{21 "msg": controllers.Msg,22 "timeMachine": controllers.TimeMachine,23 "year": controllers.GetCurrentYear,24 "pieceColor": memorygame.GetColorPiece,25 "cornerClass": memorygame.GetCornerClass,26}27func main() {28 releaseMode := os.Args[2] != "dev"29 //The app goes release mode when the configuration user is not dev30 if releaseMode {31 gin.SetMode(gin.ReleaseMode)32 }33 //Set logger behavior34 //Define the log files, open or create them with full permissions granted35 f, _ := os.OpenFile(models.Conf.LogDir+models.Conf.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)36 ferr, _ := os.OpenFile(models.Conf.LogDir+models.Conf.ErrLogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)37 //Set the gin logger to also write in the file38 multiWriter := io.MultiWriter(f, os.Stdout)39 errWriter := io.MultiWriter(ferr, os.Stdout)40 gin.DefaultWriter = multiWriter41 gin.DefaultErrorWriter = errWriter42 //Add a prefix to the alternative logger43 log.SetPrefix("[LOG] ")44 //Set the other logger to also write in the file45 log.SetOutput(multiWriter)46 //Init gin router47 r := gin.New()48 //Init language files49 controllers.InitBundle()50 //This path is used for resources (css, img, js). The sitemap can also be placed here51 r.Static("/resources", "./resources")52 //Declares which functions we can use in templates53 r.SetFuncMap(funcMap)54 //This path is used for templates.55 //** fetches every directory in /views, and * fetches every template in each directory56 r.LoadHTMLGlob("views/**/*")57 //Global middleware, used before every request. Allows to always get the preferred language58 r.Use(func(c *gin.Context) {59 //Get the preferred language from the "Accept-Language" request header60 lang := c.Request.Header.Get("Accept-Language")61 //Set the lang parameter to be used by the render function62 c.Set("lang", lang)63 c.Next()64 })65 //Recovers from any Panic and render a 500 error page66 //while logging an error id to allow simple retrieval via67 //the id we communicate on the page68 r.Use(gin.CustomRecovery(func(c *gin.Context, err interface{}) {69 errorCode := persistence.GenerateUID()70 var logger *log.Logger71 logger = log.New(gin.DefaultErrorWriter, "[ERR] ", log.LstdFlags)72 errStr := []byte(fmt.Sprintf("%v", err))73 logger.Print("Error '" + string(errStr) + "' logged with " + errorCode)74 lang := controllers.GetLang(c)75 title := controllers.MsgStr("500.title", lang, string(errStr))76 content := controllers.MsgStr("500.content", lang, errorCode)77 c.HTML(http.StatusInternalServerError, "error.html", controllers.Render(c, gin.H{"title": "500",78 "titleError": template.HTML(title), "contentError": template.HTML(content)}))79 }))80 //Set the Gin logger to ignore logging the fetching of resources (ex: images)81 r.Use(gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/resources/*"}}))82 //Routes to be handled by the router83 r.GET("/", func(c *gin.Context) {84 c.HTML(http.StatusOK, "index.html", controllers.Render(c, gin.H{"title": "index"}))85 })86 r.GET("/career", func(c *gin.Context) {87 c.HTML(http.StatusOK, "career.html", controllers.Render(c, gin.H{"title": "career"}))88 })89 r.GET("/projects", func(c *gin.Context) {90 c.HTML(http.StatusOK, "projects.html", controllers.Render(c, gin.H{"title": "projects"}))91 })92 r.GET("/contact", func(c *gin.Context) {93 c.HTML(http.StatusOK, "contact.html", controllers.Render(c, gin.H{"title": "contact"}))94 })95 r.GET("/shelf", func(c *gin.Context) {96 c.HTML(http.StatusOK, "shelf.html", controllers.Render(c, gin.H{"title": "shelf"}))97 })98 r.GET("/about/bootstrap", func(c *gin.Context) {99 lang := controllers.GetLang(c)100 titleContent := controllers.MsgStr("bootstrap.main.title", lang, nil)101 textContent := controllers.MsgStr("bootstrap.main.content", lang, nil)102 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,103 gin.H{"title": "bootstrap", "image": "bootstrap.svg",104 "credits": "", "titleContent": titleContent, "textContent": textContent,105 "website": "https://getbootstrap.com/", "wiki": "https://en.wikipedia.org/wiki/Bootstrap_(framework)"}))106 })107 r.GET("/about/play", func(c *gin.Context) {108 lang := controllers.GetLang(c)109 titleContent := controllers.MsgStr("play.main.title", lang, nil)110 textContent := controllers.MsgStr("play.main.content", lang, nil)111 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,112 gin.H{"title": "play", "image": "play.svg",113 "credits": "", "titleContent": titleContent, "textContent": textContent,114 "website": "https://www.playframework.com/", "wiki": "https://en.wikipedia.org/wiki/Play_Framework"}))115 })116 r.GET("/about/letsencrypt", func(c *gin.Context) {117 lang := controllers.GetLang(c)118 titleContent := controllers.MsgStr("letsencrypt.main.title", lang, nil)119 textContent := controllers.MsgStr("letsencrypt.main.content", lang, nil)120 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,121 gin.H{"title": "letsencrypt", "image": "letsencrypt.svg",122 "credits": "", "titleContent": titleContent, "textContent": textContent,123 "website": "https://letsencrypt.org/", "wiki": "https://en.wikipedia.org/wiki/Let%27s_Encrypt"}))124 })125 r.GET("/about/gandi", func(c *gin.Context) {126 lang := controllers.GetLang(c)127 titleContent := controllers.MsgStr("gandi.main.title", lang, nil)128 textContent := controllers.MsgStr("gandi.main.content", lang, nil)129 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,130 gin.H{"title": "gandi", "image": "gandi.svg",131 "credits": "", "titleContent": titleContent, "textContent": textContent,132 "website": "https://www.gandi.net/en", "wiki": "https://en.wikipedia.org/wiki/Gandi"}))133 })134 r.GET("/about/go", func(c *gin.Context) {135 lang := controllers.GetLang(c)136 titleContent := controllers.MsgStr("go.main.title", lang, nil)137 textContent := controllers.MsgStr("go.main.content", lang, nil)138 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,139 gin.H{"title": "go", "image": "go.svg",140 "credits": "", "titleContent": titleContent, "textContent": textContent,141 "website": "https://golang.org/", "wiki": "https://fr.wikipedia.org/wiki/Go_(langage)"}))142 })143 r.GET("/about/gin", func(c *gin.Context) {144 lang := controllers.GetLang(c)145 titleContent := controllers.MsgStr("gin.main.title", lang, nil)146 textContent := controllers.MsgStr("gin.main.content", lang, nil)147 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,148 gin.H{"title": "gin", "image": "gin.png",149 "credits": "", "titleContent": titleContent, "textContent": template.HTML(textContent),150 "website": "https://gin-gonic.com/"}))151 })152 r.GET("/about/rouen", func(c *gin.Context) {153 lang := controllers.GetLang(c)154 credits := controllers.MsgStr("rouen.credits", lang, nil)155 titleContent := controllers.MsgStr("rouen.main.title", lang, nil)156 textContent := controllers.MsgStr("rouen.main.content", lang, nil)157 c.HTML(http.StatusOK, "wiki.html", controllers.Render(c,158 gin.H{"title": "rouen", "image": "rouen.jpg",159 "credits": credits, "titleContent": titleContent, "textContent": textContent,160 "website": "https://rouen.fr/", "wiki": "https://fr.wikipedia.org/wiki/Rouen"}))161 })162 r.GET("/tools/memory", func(c *gin.Context) {163 c.HTML(http.StatusOK, "memory.html", controllers.Render(c, gin.H{"title": "memory"}))164 })165 r.GET("/tools/memory/game", func(c *gin.Context) {166 game := memorygame.GetSetMemoryGame(c)167 c.HTML(http.StatusOK, "memorygame.html", controllers.Render(c, gin.H{"title": "memory", "board": game, "pieceType": memorygame.PieceType, "gameState": memorygame.GameState}))168 })169 r.GET("/tools/memory/game/reset", memorygame.Reset())170 r.GET("/tools/memory/game/finish", memorygame.Finish())171 r.GET("/tools/time", func(c *gin.Context) {172 c.HTML(http.StatusOK, "time.html", controllers.Render(c, gin.H{"title": "time"}))173 })174 r.GET("/tools/memory/game/row/:rowId/piece/:pieceId/type", memorygame.GetPieceType())175 r.POST("/contact/mail", controllers.SendMail())176 r.GET("/tools/time/get/:query/:year/:month/:day/:hour/:minute", controllers.GetTimeMachine())177 r.GET("/about/2.0", func(c *gin.Context) {178 c.HTML(http.StatusOK, "version.html", controllers.Render(c, gin.H{"title": "version"}))179 })180 r.GET("/sitemap.xml", controllers.RenderSitemap())181 //Display a page for routes not found (error 404)182 r.NoRoute(func(c *gin.Context) {183 lang := controllers.GetLang(c)184 title := controllers.MsgStr("404.title", lang, c.Request.URL)185 content := controllers.MsgStr("404.content", lang, nil)186 c.HTML(http.StatusInternalServerError, "error.html", controllers.Render(c, gin.H{"title": "404",187 "titleError": template.HTML(title), "contentError": template.HTML(content)}))188 })189 //Generate the sitemap at each startup190 controllers.GenerateSitemap(r)191 //Launch the logs management routine192 routines.ManageLogsRoutine()193 //Launch the server at the configured TCP port194 _ = r.Run(":" + strconv.Itoa(models.Conf.Port))195}...
mackdown.go
Source:mackdown.go
1package main2import (3 "bytes"4 "errors"5 "io"6 "io/ioutil"7 "log"8 "strings"9 "github.com/0opslab/autngo"10 "github.com/gookit/color"11 "github.com/microcosm-cc/bluemonday"12 "github.com/russross/blackfriday"13 "golang.org/x/net/html"14)15func color_markdown_print(content string) {16 // å©ç¨ bluemonday 解æ17 unsafe := blackfriday.Run([]byte(content))18 htmlContent := string(bluemonday.UGCPolicy().SanitizeBytes(unsafe))19 //fmt.Println(htmlContent)20 doc, err := html.Parse(strings.NewReader(htmlContent))21 if err != nil {22 log.Panic(err)23 }24 bn, err := Body(doc)25 if err != nil {26 return27 }28 h1 := color.HEXStyle("FFFFFF", "FF0000")29 h2 := color.HEXStyle("FFFFFF", "FF0000")30 h3 := color.HEXStyle("FFFFFF", "FF0000")31 h4 := color.HEXStyle("FFFFFF", "FF0000")32 h5 := color.HEXStyle("FFFFFF", "FF0000")33 h6 := color.HEXStyle("FFFFFF", "FF0000")34 Code := color.Success35 Comment := color.Gray36 for cc := bn.FirstChild; cc != nil; cc = cc.NextSibling {37 text := &bytes.Buffer{}38 collectText(cc, text)39 textContent := text.String()40 switch cc.Data {41 case "h1":42 h1.Println(textContent)43 case "h2":44 h2.Println(textContent)45 case "h3":46 h3.Println(textContent)47 case "h4":48 h4.Println(textContent)49 case "h5":50 h5.Println(textContent)51 case "h6":52 h6.Println(textContent)53 case "p":54 p := renderNode(cc)55 pLen := len(p)56 p = p[3 : pLen-4]57 if strings.HasPrefix(p, "\n<code>") {58 codeLine := strings.Split(p, "\n")59 codeLen := len(codeLine)60 for i := 1; i < codeLen-1; i++ {61 line := codeLine[i]62 if strings.HasPrefix(line, "#") {63 color.Gray.Println()64 //Comment.Println(line)65 } else {66 color.Green.Println(line)67 }68 }69 } else {70 Comment.Println(textContent)71 }72 default:73 Code.Println(textContent)74 }75 }76}77func renderNode(n *html.Node) string {78 var buf bytes.Buffer79 w := io.Writer(&buf)80 html.Render(w, n)81 return buf.String()82}83func collectText(n *html.Node, buf *bytes.Buffer) {84 if n.Type == html.TextNode {85 buf.WriteString(n.Data)86 }87 for c := n.FirstChild; c != nil; c = c.NextSibling {88 collectText(c, buf)89 }90}91func Body(doc *html.Node) (*html.Node, error) {92 var body *html.Node93 var crawler func(*html.Node)94 crawler = func(node *html.Node) {95 if node.Type == html.ElementNode && node.Data == "body" {96 body = node97 return98 }99 for child := node.FirstChild; child != nil; child = child.NextSibling {100 crawler(child)101 }102 }103 crawler(doc)104 if body != nil {105 return body, nil106 }107 return nil, errors.New("Missing <body> in the node tree")108}109func main() {110 //confile := flag.String("conf", "", "the configuration file")111 //flag.Parse()112 //if *confile == "" {113 // fmt.Println("Please specify the configuration file")114 // return115 //}116 cmdPath := "/data/workspace/useful-command"117 files, _, _ := autngo.FileHepler.WalkDirFiles(cmdPath, "md")118 for _, file := range files {119 fileContent, err := ioutil.ReadFile(file)120 if err != nil {121 color.Red.Println("ReadFileError")122 return123 }124 color_markdown_print(string(fileContent))125 }126}...
TextContent
Using AI Code Generation
1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("div", func(e *colly.HTMLElement) {5 fmt.Println(e.Text)6 })7}8Web Scraping is a technique to automatically access and extract large amounts of information from a website, which can save a huge amount of time and effort. Web Scraping is also referred to as web data extraction, web harvesting, or web data mining. Web Scraping is a technique used to extract large amounts of data from websites whereby the data is extracted and saved to a local file in your computer or to a database in table (spreadsheet) format. Web scraping software may access the World Wide Web directly using the Hypertext Transfer Protocol, or through a web browser. While web scraping can be done manually by a software user, the term typically refers to automated processes implemented using a bot or web crawler. It is a form of copying, in which specific data is gathered and copied from the web, typically into a central local database or spreadsheet, for later retrieval or analysis. Web scraping a web page involves fetching it and extracting from it. Fetching is the downloading of a page (which a browser does when a user views the page). Therefore, web crawling is a main component of web scraping, to fetch pages for later processing. Once fetched, then extraction can take place. The content of a page may be parsed, searched, reformatted, its data copied into a spreadsheet, and so on. Web scraping software may access the World Wide Web directly using the Hypertext Transfer Protocol, or through a web browser. While web scraping can be done manually by a software user, the term typically refers to automated processes implemented using a bot or web crawler. It is a form of copying, in which specific data is gathered and copied from the web, typically into a central local database or spreadsheet, for later retrieval or analysis. Web scraping a web page involves fetching it and extracting from it. Fetching is the downloading of a page (which a browser does when a user views the page). Therefore, web crawling is a main component of web scraping, to fetch pages for later processing. Once fetched, then extraction can take place. The content of a page may be parsed, searched, reform
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 doc.Find("title").Each(func(i int, s *goquery.Selection) {7 fmt.Println(s.Text())8 })9}10import (11func main() {12 if err != nil {13 log.Fatal(err)14 }15 doc.Find("title").Each(func(i int, s *goquery.Selection) {16 fmt.Println(s.Text())17 })18}19import (20func main() {21 if err != nil {22 log.Fatal(err)23 }24 doc.Find("title").Each(func(i int, s *goquery.Selection) {25 fmt.Println(s.Text())26 })27}28import (29func main() {30 if err != nil {31 log.Fatal(err)32 }33 doc.Find("title").Each(func(i int, s *goquery.Selection) {34 fmt.Println(s.Text())35 })36}37import (38func main() {39 if err != nil {40 log.Fatal(err)41 }42 doc.Find("title").Each(func(i int, s *goquery.Selection) {43 fmt.Println(s.Text())44 })45}46import (
TextContent
Using AI Code Generation
1import (2func main() {3 for _, url := range os.Args[1:] {4 }5 resp, err := http.Get(url)6 if err != nil {7 fmt.Fprintf(os.Stderr, "fetch: %v8 os.Exit(1)9 }10 b, err := ioutil.ReadAll(resp.Body)11 resp.Body.Close()12 if err != nil {13 fmt.Fprintf(os.Stderr, "fetch: reading %s: %v14 os.Exit(1)15 }16 doc, err := html.Parse(resp.Body)17 if err != nil {18 fmt.Fprintf(os.Stderr, "fetch: reading %s: %v19 os.Exit(1)20 }21 fmt.Println(b)22 fmt.Println("Text Content: ", TextContent(doc))23 }24}25func TextContent(n *html.Node) string {26 if n.Type == html.TextNode {27 }28 if n.Type == html.ElementNode && n.Data == "script" {29 }30 if n.Type == html.ElementNode && n.Data == "style" {31 }32 for c := n.FirstChild; c != nil; c = c.NextSibling {33 ret += TextContent(c)34 }35}
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 doc, err := html.Parse(resp.Body)7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println(doc.TextContent())11}12func (n *Node) TextContent() string13func (n *Node) TextContent() string14func (n *Node) TextContent() string15func (n *Node) TextContent() string16func (n *Node) TextContent() string
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println("Error:", err)5 }6 defer resp.Body.Close()7 b, err := ioutil.ReadAll(resp.Body)8 if err != nil {9 fmt.Println("Error:", err)10 }11 r := strings.NewReader(string(b))12 z := html.NewTokenizer(r)13 for {14 tt := z.Next()15 switch {16 fmt.Printf("%s17", z.Text())18 }19 }20}
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 doc, err := goquery.NewDocumentFromReader(res.Body)7 if err != nil {8 log.Fatal(err)9 }10 doc.Find(".entry-content").Each(func(i int, s *goquery.Selection) {11 fmt.Println(s.Text())12 })13}
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 panic(err)5 }6 defer res.Body.Close()7 if res.StatusCode != 200 {8 panic("status code error: %d9 }10 doc, err := goquery.NewDocumentFromReader(res.Body)11 if err != nil {12 panic(err)13 }14 doc.Find("title").Each(func(i int, s *goquery.Selection) {15 fmt.Println(s.Text())16 })17}18import (19func main() {20 if err != nil {21 panic(err)22 }23 defer res.Body.Close()24 if res.StatusCode != 200 {25 panic("status code error: %d26 }27 doc, err := goquery.NewDocumentFromReader(res.Body)28 if err != nil {29 panic(err)30 }31 doc.Find("title").Each(func(i int, s *goquery.Selection) {32 fmt.Println(s.TextContent())33 })34}35import (36func main() {37 if err != nil {38 panic(err)39 }40 defer res.Body.Close()41 if res.StatusCode != 200 {42 panic("status code error: %d43 }44 doc, err := goquery.NewDocumentFromReader(res.Body)45 if err != nil {46 panic(err)47 }48 doc.Find("title").Each(func(i int, s *goquery.Selection) {49 fmt.Println(s.Text())50 fmt.Println(s.TextContent())51 fmt.Println(s.Attribute("href"))52 })53}54import (
TextContent
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 doc.Find("table").Each(func(i int, s *goquery.Selection) {7 band := s.Find("tr").Text()8 fmt.Printf("Review %d9 fmt.Printf("Band: %s10 })11}
TextContent
Using AI Code Generation
1import "fmt"2import "github.com/jbowtie/gokogiri/html"3func main() {4 doc, err := html.Parse([]byte("<html><body>hello</body></html>"))5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(doc.Root().FirstChild().TextContent())9}10import "fmt"11import "github.com/jbowtie/gokogiri/html"12func main() {13 doc, err := html.Parse([]byte("<html><body><h1>hello</h1></body></html>"))14 if err != nil {15 fmt.Println(err)16 }17 fmt.Println(doc.Root().Search("h1").TextContent())18}19import "fmt"20import "github.com/jbowtie/gokogiri/html"21func main() {22 doc, err := html.Parse([]byte("<html><body><h1>hello</h1></body></html>"))23 if err != nil {24 fmt.Println(err)25 }26}27import "fmt"28import "github.com/jbowtie/gokogiri/html"29func main() {30 doc, err := html.Parse([]byte("<html><body><h1>hello</h1></body></html>"))31 if err != nil {32 fmt.Println(err)33 }34}35import "fmt"36import "github.com/jbowtie/gokogiri/html"37func main() {38 doc, err := html.Parse([]byte("<html><body><h1>hello</h1></body></html>"))39 if err != nil {40 fmt.Println(err)41 }42}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!