Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async function injectCNPJ() {
- const cnpj = "59787635000123";
- // Função para disparar a alteração reconhecida pelo React
- function setReactInputValue(input, value) {
- const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
- window.HTMLInputElement.prototype,
- "value"
- ).set;
- nativeInputValueSetter.call(input, value);
- input.dispatchEvent(new Event("input", { bubbles: true }));
- input.dispatchEvent(new Event("change", { bubbles: true }));
- }
- // Função para aguardar um elemento aparecer no DOM
- function waitForElement(selector, timeout = 2000) {
- return new Promise((resolve) => {
- const start = Date.now();
- const interval = setInterval(() => {
- const el = document.querySelector(selector);
- if (el || Date.now() - start > timeout) {
- clearInterval(interval);
- resolve(el);
- }
- }, 50);
- });
- }
- // Localiza todos os botões "reference"
- const referenceButtons = Array.from(
- document.querySelectorAll('span[aria-controls^="radix-"], [data-state="closed"]')
- ).filter((el) => el.textContent.trim().toLowerCase() === "reference");
- if (referenceButtons.length === 0) {
- console.warn("Nenhum elemento 'reference' encontrado.");
- return;
- }
- console.log(`Processando ${referenceButtons.length} itens...`);
- for (const btn of referenceButtons) {
- // 1. Clica no botão para abrir o modal
- btn.click();
- // 2. Aguarda o input do modal abrir
- const inputField = await waitForElement(
- 'div[role="dialog"] input, [data-state="open"] input, input[type="text"]'
- );
- if (inputField) {
- inputField.focus();
- // 3. Injeta o CNPJ de forma compatível com React
- setReactInputValue(inputField, cnpj);
- await new Promise((r) => setTimeout(r, 150));
- // 4. Localiza e clica no botão de confirmar dentro do modal
- const confirmBtn = Array.from(
- document.querySelectorAll('div[role="dialog"] button, [data-state="open"] button')
- ).find((b) => {
- const txt = b.textContent.trim().toLowerCase();
- return txt.includes("confirmar") || txt.includes("confirm") || txt.includes("ok") || txt.includes("salvar");
- });
- if (confirmBtn) {
- confirmBtn.click();
- }
- }
- // Pequena pausa entre cada item para evitar travamentos
- await new Promise((r) => setTimeout(r, 300));
- }
- console.log("Todos os campos foram preenchidos!");
- })();
Advertisement
Add Comment
Please, Sign In to add comment