antonio_pedro

[BOT] 17track

Jul 21st, 2026
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. (async function injectCNPJ() {
  2. const cnpj = "59787635000123";
  3.  
  4. // Função para disparar a alteração reconhecida pelo React
  5. function setReactInputValue(input, value) {
  6. const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
  7. window.HTMLInputElement.prototype,
  8. "value"
  9. ).set;
  10. nativeInputValueSetter.call(input, value);
  11.  
  12. input.dispatchEvent(new Event("input", { bubbles: true }));
  13. input.dispatchEvent(new Event("change", { bubbles: true }));
  14. }
  15.  
  16. // Função para aguardar um elemento aparecer no DOM
  17. function waitForElement(selector, timeout = 2000) {
  18. return new Promise((resolve) => {
  19. const start = Date.now();
  20. const interval = setInterval(() => {
  21. const el = document.querySelector(selector);
  22. if (el || Date.now() - start > timeout) {
  23. clearInterval(interval);
  24. resolve(el);
  25. }
  26. }, 50);
  27. });
  28. }
  29.  
  30. // Localiza todos os botões "reference"
  31. const referenceButtons = Array.from(
  32. document.querySelectorAll('span[aria-controls^="radix-"], [data-state="closed"]')
  33. ).filter((el) => el.textContent.trim().toLowerCase() === "reference");
  34.  
  35. if (referenceButtons.length === 0) {
  36. console.warn("Nenhum elemento 'reference' encontrado.");
  37. return;
  38. }
  39.  
  40. console.log(`Processando ${referenceButtons.length} itens...`);
  41.  
  42. for (const btn of referenceButtons) {
  43. // 1. Clica no botão para abrir o modal
  44. btn.click();
  45.  
  46. // 2. Aguarda o input do modal abrir
  47. const inputField = await waitForElement(
  48. 'div[role="dialog"] input, [data-state="open"] input, input[type="text"]'
  49. );
  50.  
  51. if (inputField) {
  52. inputField.focus();
  53.  
  54. // 3. Injeta o CNPJ de forma compatível com React
  55. setReactInputValue(inputField, cnpj);
  56.  
  57. await new Promise((r) => setTimeout(r, 150));
  58.  
  59. // 4. Localiza e clica no botão de confirmar dentro do modal
  60. const confirmBtn = Array.from(
  61. document.querySelectorAll('div[role="dialog"] button, [data-state="open"] button')
  62. ).find((b) => {
  63. const txt = b.textContent.trim().toLowerCase();
  64. return txt.includes("confirmar") || txt.includes("confirm") || txt.includes("ok") || txt.includes("salvar");
  65. });
  66.  
  67. if (confirmBtn) {
  68. confirmBtn.click();
  69. }
  70. }
  71.  
  72. // Pequena pausa entre cada item para evitar travamentos
  73. await new Promise((r) => setTimeout(r, 300));
  74. }
  75.  
  76. console.log("Todos os campos foram preenchidos!");
  77. })();
Advertisement
Add Comment
Please, Sign In to add comment