(function() {
‘use strict’;
// Create a DIV CONTAINER
const body = document.body;
const divContainer = document.createElement('div');
divContainer.style.position = 'fixed';
divContainer.style.bottom = '15px';
divContainer.style.left = '15px';
body.appendChild(divContainer);
// Heading
const heading = document.createElement('h2');
heading.textContent = 'Introduce el rango de filas (Ej: 2-5) para seleccionar bolillas';
divContainer.appendChild(heading);
// Input form
const inputDiv = document.createElement('div');
const label = document.createElement('label');
label.setAttribute('for', 'row-range');
label.textContent = 'Rango de filas (Ejemplo: 2-7):';
inputDiv.appendChild(label);
const inputField = document.createElement('input');
inputField.setAttribute('type', 'text');
inputField.setAttribute('id', 'row-range');
inputField.setAttribute('placeholder', 'Ej: 2-5');
inputDiv.appendChild(inputField);
// Submit button
const submitButton = document.createElement('button');
submitButton.setAttribute('id', 'submit-btn');
submitButton.textContent = 'Seleccionar filas';
inputDiv.appendChild(submitButton);
divContainer.appendChild(inputDiv);
// Output divs
const outputDiv2 = document.createElement('div');
outputDiv2.setAttribute('id', 'output2');
divContainer.appendChild(outputDiv2);
const outputDiv = document.createElement('div');
outputDiv.setAttribute('id', 'output');
divContainer.appendChild(outputDiv);
const repeatedOutputDiv = document.createElement('div');
repeatedOutputDiv.setAttribute('id', 'repeated-output');
divContainer.appendChild(repeatedOutputDiv);
const excludedOutputDiv = document.createElement('div');
excludedOutputDiv.setAttribute('id', 'excluded-output');
divContainer.appendChild(excludedOutputDiv);
const finalListOutputDiv = document.createElement('div');
finalListOutputDiv.setAttribute('id', 'final-list-output');
divContainer.appendChild(finalListOutputDiv);
const currentNumbersOutputDiv = document.createElement('div');
currentNumbersOutputDiv.setAttribute('id', 'current-numbers-output');
divContainer.appendChild(currentNumbersOutputDiv);
const currentNumbersOutputDiv1 = document.createElement('div');
currentNumbersOutputDiv1.setAttribute('id', 'current-numbers-output1');
divContainer.appendChild(currentNumbersOutputDiv1);
const currentNumbersOutputDiv2 = document.createElement('div');
currentNumbersOutputDiv2.setAttribute('id', 'current-numbers-output2');
divContainer.appendChild(currentNumbersOutputDiv2);
// Variables
const selectedNumbers = [];
const tableRows = document.querySelectorAll('table tbody tr'); // Seleccionamos todas las filas de la tabla
// Submit button event listener
submitButton.addEventListener('click', function() {
const rowRange = inputField.value.trim();
const match = rowRange.match(/^(\d+)-(\d+)$/);
if (match) {
const startRow = parseInt(match[1], 10) - 1;
const endRow = parseInt(match[2], 10) - 1;
if (startRow >= 0 && endRow < tableRows.length && startRow <= endRow) {
selectedNumbers.length = 0;
for (let i = startRow; i <= endRow; i++) {
const bolillas = tableRows[i].cells[2].textContent.trim();
const bolillaArray = bolillas.split(' ').map(num => num.padStart(2, '0'));
selectedNumbers.push(...bolillaArray);
}
// Display selected numbers (without sorting)
document.getElementById('output2').textContent = 'Números seleccionados: ' + selectedNumbers.join(', '); // No sorting here
document.getElementById('output').textContent = 'Números seleccionados: ' + sortNumbers(selectedNumbers).join(', '); // Sorting here
displayRepeatedNumbers(selectedNumbers);
displayExcludedNumbers(selectedNumbers);
generateFinalList(selectedNumbers);
const currentRow = tableRows[startRow - 1];
const currentBolillas = currentRow ? currentRow.cells[2].textContent.trim() : '';
const currentBolillaArray = currentBolillas.split(' ').map(num => num.padStart(2, '0'));
const fila1 = tableRows[startRow];
const currentBolillasF1 = fila1 ? fila1.cells[2].textContent.trim() : '';
const currentBolillaArrayF1 = currentBolillasF1.split(' ').map(num => num.padStart(2, '0'));
const fila2 = tableRows[startRow + 1];
const currentBolillasF2 = fila2 ? fila2.cells[2].textContent.trim() : '';
const currentBolillaArrayF2 = currentBolillasF2.split(' ').map(num => num.padStart(2, '0'));
document.getElementById('current-numbers-output').textContent = 'NUMEROS QUE GANARON!!! (de fila ' + (startRow) + '): ' + sortNumbers(currentBolillaArray).join(', ');
document.getElementById('current-numbers-output1').textContent = 'Números actuales (de fila ' + (startRow+1) + '): ' + sortNumbers(currentBolillaArrayF1).join(', ');
document.getElementById('current-numbers-output2').textContent = 'Números actuales (de fila ' + (startRow + 2) + '): ' + sortNumbers(currentBolillaArrayF2).join(', ');
} else {
alert('El rango de filas es inválido o fuera de los límites.');
}
} else {
alert('Por favor, ingresa un rango válido de filas (Ejemplo: 2-5).');
}
});
// Function to display repeated numbers
function displayRepeatedNumbers(numbers) {
const frequency = {};
numbers.forEach(num => {
frequency[num] = (frequency[num] || 0) + 1;
});
const repeatedNumbers = Object.keys(frequency).filter(num => frequency[num] > 1);
if (repeatedNumbers.length > 0) {
document.getElementById('repeated-output').textContent = 'Números repetidos: ' + sortNumbers(repeatedNumbers).join(', ');
} else {
document.getElementById('repeated-output').textContent = '';
}
}
// Function to display excluded numbers
function displayExcludedNumbers(numbers) {
const frequency = {};
numbers.forEach(num => {
frequency[num] = (frequency[num] || 0) + 1;
});
const excludedNumbers = Object.keys(frequency).filter(num => frequency[num] === 1);
document.getElementById('excluded-output').textContent = 'Números excluidos (sin repetidos): ' + sortNumbers(excludedNumbers).join(', ');
}
// Function to generate the final list of numbers
function generateFinalList(selectedNumbers) {
const finalList = [];
for (let i = 1; i <= 40; i++) {
if (!selectedNumbers.includes(i.toString().padStart(2, '0'))) {
finalList.push(i.toString().padStart(2, '0'));
}
}
const repeatedNumbers = document.getElementById('repeated-output').textContent.split(': ')[1];
if (repeatedNumbers) {
finalList.push(...repeatedNumbers.split(', ').map(num => num.padStart(2, '0')));
}
const uniqueFinalList = [...new Set(finalList)];
document.getElementById('final-list-output').textContent = 'Lista final de números (excluyendo seleccionados y añadiendo repetidos): ' + sortNumbers(uniqueFinalList).join(', ');
}
// Function to sort numbers in ascending order
function sortNumbers(numbers) {
return numbers.sort((a, b) => parseInt(a) - parseInt(b));
}
})();