Welcome Guest ( Log In  ·  Register)



 
Reply to this topicStart Poll
Another frontend question. Help me.
[ Standard ] · Linear+
IamGroot
post Nov 21 2023, 01:09 PM
Post #1


Lieutenant
Group Icon

Group: Members
Posts: 502

Submissions: None
Joined: 30-March 21

Member No.: 125,269






This is a lottery, I would like to choose 6 random numbers from 60.
I would like to create a Greasymonkey script to do this automatically on page load. Can you help me?

CODE
</table>
<form action=lotto_feldolgoz.php method=post>
<table width=600 align="center">
<tr height=30><td align=center class=thead colspan=15><img src="pic/lottery.png" alt="" width="23" height="23" /><b>Szelvény kitöltése</b><img src="pic/lottery.png" alt="" width="24" height="24" /></td></tr>
<tr><td>01<input type=checkbox name=lottoszam[] value=1></td><td>02<input type=checkbox name=lottoszam[] value=2></td><td>03<input type=checkbox name=lottoszam[] value=3></td><td>04<input type=checkbox name=lottoszam[] value=4></td><td>05<input type=checkbox name=lottoszam[] value=5></td><td>06<input type=checkbox name=lottoszam[] value=6></td><td>07<input type=checkbox name=lottoszam[] value=7></td><td>08<input type=checkbox name=lottoszam[] value=8></td><td>09<input type=checkbox name=lottoszam[] value=9></td><td>10<input type=checkbox name=lottoszam[] value=10></td><td>11<input type=checkbox name=lottoszam[] value=11></td><td>12<input type=checkbox name=lottoszam[] value=12></td><td>13<input type=checkbox name=lottoszam[] value=13></td><td>14<input type=checkbox name=lottoszam[] value=14></td><td>15<input type=checkbox name=lottoszam[] value=15></td></tr>
<tr><td>16<input type=checkbox name=lottoszam[] value=16></td><td>17<input type=checkbox name=lottoszam[] value=17></td><td>18<input type=checkbox name=lottoszam[] value=18></td><td>19<input type=checkbox name=lottoszam[] value=19></td><td>20<input type=checkbox name=lottoszam[] value=20></td><td>21<input type=checkbox name=lottoszam[] value=21></td><td>22<input type=checkbox name=lottoszam[] value=22></td><td>23<input type=checkbox name=lottoszam[] value=23></td><td>24<input type=checkbox name=lottoszam[] value=24></td><td>25<input type=checkbox name=lottoszam[] value=25></td><td>26<input type=checkbox name=lottoszam[] value=26></td><td>27<input type=checkbox name=lottoszam[] value=27></td><td>28<input type=checkbox name=lottoszam[] value=28></td><td>29<input type=checkbox name=lottoszam[] value=29></td><td>30<input type=checkbox name=lottoszam[] value=30></td></tr>
<tr><td>31<input type=checkbox name=lottoszam[] value=31></td><td>32<input type=checkbox name=lottoszam[] value=32></td><td>33<input type=checkbox name=lottoszam[] value=33></td><td>34<input type=checkbox name=lottoszam[] value=34></td><td>35<input type=checkbox name=lottoszam[] value=35></td><td>36<input type=checkbox name=lottoszam[] value=36></td><td>37<input type=checkbox name=lottoszam[] value=37></td><td>38<input type=checkbox name=lottoszam[] value=38></td><td>39<input type=checkbox name=lottoszam[] value=39></td><td>40<input type=checkbox name=lottoszam[] value=40></td><td>41<input type=checkbox name=lottoszam[] value=41></td><td>42<input type=checkbox name=lottoszam[] value=42></td><td>43<input type=checkbox name=lottoszam[] value=43></td><td>44<input type=checkbox name=lottoszam[] value=44></td><td>45<input type=checkbox name=lottoszam[] value=45></td></tr>
<tr><td>46<input type=checkbox name=lottoszam[] value=46></td><td>47<input type=checkbox name=lottoszam[] value=47></td><td>48<input type=checkbox name=lottoszam[] value=48></td><td>49<input type=checkbox name=lottoszam[] value=49></td><td>50<input type=checkbox name=lottoszam[] value=50></td><td>51<input type=checkbox name=lottoszam[] value=51></td><td>52<input type=checkbox name=lottoszam[] value=52></td><td>53<input type=checkbox name=lottoszam[] value=53></td><td>54<input type=checkbox name=lottoszam[] value=54></td><td>55<input type=checkbox name=lottoszam[] value=55></td><td>56<input type=checkbox name=lottoszam[] value=56></td><td>57<input type=checkbox name=lottoszam[] value=57></td><td>58<input type=checkbox name=lottoszam[] value=58></td><td>59<input type=checkbox name=lottoszam[] value=59></td><td>60<input type=checkbox name=lottoszam[] value=60></td></tr>
<tr>
 <td align=center colspan=15 height=30 class=thead><img src="pic/lottery.png" alt="" width="22" height="22" />
 <input type='submit' class='btn' value='Feladom a szelvényt!' title='Még nincs kész'>
 <img src="pic/lottery.png" alt="" width="22" height="22" /></td>
</tr>
</table></form>
</tr>
</table>

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Mirez
post Nov 27 2023, 07:07 AM
Post #2


Grand Hustle Pimp
Group Icon

Group: Members
Posts: 16,270

Submissions: None
Joined: 12-October 06

From: Niflheim
Member No.: 46,031

Gamertag: IamMirezNL





Sure, I can help you with that. Here is a Greasemonkey script that will select 6 random numbers from 60 on page load:

JavaScript
CODE
// ==UserScript==
// @name        Lottery Number Picker
// @namespace   Lottery
// @description Automatically picks 6 random numbers on lottery page load
// @include     YOUR_URL_HERE
// @version     1
// @grant       none
// ==/UserScript==

window.addEventListener('load', function() {
   let checkboxes = Array.from(document.querySelectorAll('input[type=checkbox][name="lottoszam[]"]'));
   let randomNumbers = [];
   while(randomNumbers.length < 6) {
       let randomNumber = Math.floor(Math.random() * 60);
       if(!randomNumbers.includes(randomNumber)) {
           randomNumbers.push(randomNumber);
           checkboxes[randomNumber].checked = true;
       }
   }
}, false);

Please replace YOUR_URL_HERE with the URL of your lottery page. This script will run every time the page loads, selecting 6 random checkboxes. Please note that this script assumes that the checkboxes are in the same order as their values (i.e., the first checkbox has a value of 1, the second a value of 2, and so on up to 60). If the checkboxes are not in this order, the script will need to be adjusted.

Remember to install the Greasemonkey extension and add this script to it. Let me know if you need further assistance! ????

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
IamGroot
post Nov 27 2023, 10:33 AM
Post #3


Lieutenant
Group Icon

Group: Members
Posts: 502

Submissions: None
Joined: 30-March 21

Member No.: 125,269






QUOTE(Mirez @ Nov 27 2023, 01:07 PM)
Sure, I can help you with that. Here is a Greasemonkey script that will select 6 random numbers from 60 on page load:

JavaScript
CODE
// ==UserScript==
// @name        Lottery Number Picker
// @namespace   Lottery
// @description Automatically picks 6 random numbers on lottery page load
// @include     YOUR_URL_HERE
// @version     1
// @grant       none
// ==/UserScript==

window.addEventListener('load', function() {
   let checkboxes = Array.from(document.querySelectorAll('input[type=checkbox][name="lottoszam[]"]'));
   let randomNumbers = [];
   while(randomNumbers.length < 6) {
       let randomNumber = Math.floor(Math.random() * 60);
       if(!randomNumbers.includes(randomNumber)) {
           randomNumbers.push(randomNumber);
           checkboxes[randomNumber].checked = true;
       }
   }
}, false);

Please replace YOUR_URL_HERE with the URL of your lottery page. This script will run every time the page loads, selecting 6 random checkboxes. Please note that this script assumes that the checkboxes are in the same order as their values (i.e., the first checkbox has a value of 1, the second a value of 2, and so on up to 60). If the checkboxes are not in this order, the script will need to be adjusted.

Remember to install the Greasemonkey extension and add this script to it. Let me know if you need further assistance! ????
*


Fantastic, it works. Thank you very much.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Mirez
post Nov 28 2023, 09:37 AM
Post #4


Grand Hustle Pimp
Group Icon

Group: Members
Posts: 16,270

Submissions: None
Joined: 12-October 06

From: Niflheim
Member No.: 46,031

Gamertag: IamMirezNL





You're welcome, I don't know the first thing about frontend development but I just asked your question to ChatGPT and copy/pasted the answer.



User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicTopic Options
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
 




Time is now: 1st March 2024 - 10:45 PM
About Us  ·   Advertising  ·   Contact Us  ·   Terms of Use  ·   Privacy Policy