// Create the button const button = document.createElement('button'); button.textContent = 'העלה קובץ'; button.style.backgroundColor = 'green'; button.style.color = 'white'; button.style.padding = '5px'; button.style.border = 'none'; button.style.borderRadius = '5px'; button.style.margin = '5px'; // Create the progress element const progress = document.createElement('progress'); progress.style.width = '99%'; progress.style.height = '5px'; progress.style.backgroundColor = 'grey'; // Create the progress bar inside the progress element const progressBar = document.createElement('div'); progressBar.style.width = '0%'; progressBar.style.height = '100%'; progressBar.style.backgroundColor = 'blue'; // Append the progress bar to the progress element progress.appendChild(progressBar); // Find the target element to insert the button and progress element before const targetElement = document.querySelector('.flex.flex-col.w-full.py-2.flex-grow.md\\:py-3.md\\:pl-4'); // Insert the button and progress element before the target element targetElement.parentNode.insertBefore(button, targetElement); targetElement.parentNode.insertBefore(progress, targetElement); // Function to submit conversation chunk async function submitConversation(text, part, filename) { const textarea = document.querySelector("textarea[tabindex='0']"); const enterKeyEvent = new KeyboardEvent("keydown", { bubbles: true, cancelable: true, keyCode: 13, }); textarea.value = `Part ${part} of ${filename}: \n\n ${text}`; textarea.dispatchEvent(enterKeyEvent); } // Check if chatgpt is ready let chatgptReady = false; const checkChatGPT = async () => { while (!chatgptReady) { await new Promise(resolve => setTimeout(resolve, 1000)); chatgptReady = !document.querySelector(".text-2xl > span:not(.invisible)"); } }; // Handle file selection button.addEventListener('click', async () => { const input = document.createElement('input'); input.type = 'file'; input.accept = '.txt, .js, .py, .html, .css, .json, .csv'; input.addEventListener('change', async () => { const file = input.files[0]; const reader = new FileReader(); const chunkSize = 15000; let offset = 0; const numChunks = Math.ceil(file.size / chunkSize); reader.onload = async (event) => { const text = event.target.result; const part = Math.ceil(offset / chunkSize) + 1; const filename = file.name; await submitConversation(text, part, filename); progressBar.style.width = `${((part) / numChunks) * 100}%`; offset += chunkSize; if (offset < file.size) { reader.readAsText(file.slice(offset, offset + chunkSize)); } else { progressBar.style.backgroundColor = 'blue'; await checkChatGPT(); // All chunks have been submitted, perform final actions here } }; reader.readAsText(file.slice(offset, offset + chunkSize)); }); input.click(); });