From 376546ff630eb9aabd3066fd71232e86ee48f4c7 Mon Sep 17 00:00:00 2001 From: Izidorio Bento Date: Thu, 16 Feb 2023 07:25:14 -0300 Subject: [PATCH] fix add manifest v3 --- build.sh | 3 + manifest.json | 36 ++--- src/assets/icons/{icon128.png => 128x128.png} | Bin src/assets/icons/{icon16.png => 16x16.png} | Bin src/assets/icons/{icon24.png => 32x32.png} | Bin src/assets/icons/{icon48.png => 48x48.png} | Bin src/content.js | 7 + src/html/background.html | 1 - src/js/background.js | 1 - src/js/content_main.js | 5 - src/js/content_script.js | 5 - src/js/models/handle.js | 66 --------- src/js/models/setButtons.js | 134 ------------------ src/js/models/template.js | 51 ------- src/js/models/user.js | 13 -- src/js/models/utils.js | 109 -------------- src/modules/handle.js | 58 ++++++++ src/modules/index.js | 3 + src/modules/main.js | 133 +++++++++++++++++ src/{js/models => modules}/scraping.js | 15 +- src/modules/template.js | 49 +++++++ src/modules/utils.js | 100 +++++++++++++ 22 files changed, 383 insertions(+), 406 deletions(-) create mode 100755 build.sh rename src/assets/icons/{icon128.png => 128x128.png} (100%) rename src/assets/icons/{icon16.png => 16x16.png} (100%) rename src/assets/icons/{icon24.png => 32x32.png} (100%) rename src/assets/icons/{icon48.png => 48x48.png} (100%) create mode 100644 src/content.js delete mode 100644 src/html/background.html delete mode 100644 src/js/background.js delete mode 100644 src/js/content_main.js delete mode 100644 src/js/content_script.js delete mode 100644 src/js/models/handle.js delete mode 100644 src/js/models/setButtons.js delete mode 100644 src/js/models/template.js delete mode 100644 src/js/models/user.js delete mode 100644 src/js/models/utils.js create mode 100644 src/modules/handle.js create mode 100644 src/modules/index.js create mode 100644 src/modules/main.js rename src/{js/models => modules}/scraping.js (87%) create mode 100644 src/modules/template.js create mode 100644 src/modules/utils.js diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..05200d8 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +# ! /Bin /bash +echo "empacotanto o sistema .... \n" +zip -r addon-zappull.zip src manifest.json \ No newline at end of file diff --git a/manifest.json b/manifest.json index 73587f9..e3a0edc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,24 +1,28 @@ { - "manifest_version": 2, "name": "ZapPull", - "version": "0.6.2", - "description": "Extensão que baixa em .csv ou copia para a área de transferência os participantes dos Grupos do WhatsApp. https://github.com/izidorio/addon-zappull", - "author": "Izidorio Bento ", - "icons": { - "16": "src/assets/icons/icon16.png", - "48": "src/assets/icons/icon48.png", - "128": "src/assets/icons/icon128.png" - }, - "background": { - "page": "src/html/background.html" - }, + "description": "Exportar os participantes dos Grupos do WhatsApp. https://github.com/izidorio/addon-zappull", + "version": "1.0.0", + "manifest_version": 3, + "author": "Bento, Izidorio ", + "permissions": ["activeTab", "scripting", "storage"], + "host_permissions": ["https://web.whatsapp.com/"], "content_scripts": [ { - "matches": ["https://web.whatsapp.com/"], - "js": ["src/js/content_script.js"], + "matches": ["https://web.whatsapp.com/*"], + "js": ["src/content.js"], "css": ["src/assets/style.css"] } ], - "permissions": ["https://web.whatsapp.com/"], - "web_accessible_resources": ["src/js/*"] + "web_accessible_resources": [ + { + "resources": ["src/modules/*.js"], + "matches": ["https://web.whatsapp.com/*"] + } + ], + "icons": { + "16": "src/assets/icons/16x16.png", + "32": "src/assets/icons/32x32.png", + "48": "src/assets/icons/48x48.png", + "128": "src/assets/icons/128x128.png" + } } diff --git a/src/assets/icons/icon128.png b/src/assets/icons/128x128.png similarity index 100% rename from src/assets/icons/icon128.png rename to src/assets/icons/128x128.png diff --git a/src/assets/icons/icon16.png b/src/assets/icons/16x16.png similarity index 100% rename from src/assets/icons/icon16.png rename to src/assets/icons/16x16.png diff --git a/src/assets/icons/icon24.png b/src/assets/icons/32x32.png similarity index 100% rename from src/assets/icons/icon24.png rename to src/assets/icons/32x32.png diff --git a/src/assets/icons/icon48.png b/src/assets/icons/48x48.png similarity index 100% rename from src/assets/icons/icon48.png rename to src/assets/icons/48x48.png diff --git a/src/content.js b/src/content.js new file mode 100644 index 0000000..7d1df29 --- /dev/null +++ b/src/content.js @@ -0,0 +1,7 @@ +"use strict"; + +const script = document.createElement("script"); +script.setAttribute("type", "module"); +script.setAttribute("src", chrome.runtime.getURL("src/modules/main.js")); +const body = document.body || document.getElementsByTagName("body")[0]; +body.append(script); diff --git a/src/html/background.html b/src/html/background.html deleted file mode 100644 index cb4aced..0000000 --- a/src/html/background.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/js/background.js b/src/js/background.js deleted file mode 100644 index f32a99d..0000000 --- a/src/js/background.js +++ /dev/null @@ -1 +0,0 @@ -/*mater este arquivo*/ diff --git a/src/js/content_main.js b/src/js/content_main.js deleted file mode 100644 index 65266c1..0000000 --- a/src/js/content_main.js +++ /dev/null @@ -1,5 +0,0 @@ -import SetButtons from './models/setButtons.js'; - -export function main() { - SetButtons; -} diff --git a/src/js/content_script.js b/src/js/content_script.js deleted file mode 100644 index 65c773f..0000000 --- a/src/js/content_script.js +++ /dev/null @@ -1,5 +0,0 @@ -(async () => { - const src = chrome.extension.getURL('src/js/content_main.js'); - const contentScript = await import(src); - contentScript.main(); -})(); diff --git a/src/js/models/handle.js b/src/js/models/handle.js deleted file mode 100644 index 573191a..0000000 --- a/src/js/models/handle.js +++ /dev/null @@ -1,66 +0,0 @@ -import { readGroup, dateCreatedGroup, nameGroup, readListParticipants } from './scraping.js'; -import { saveToDataFile, copyToClipboard, addOperatorToNumbers } from './utils.js'; -import { style, card, container } from './template.js'; - -export async function saveCsv(){ - - const nameFile = nameGroup(); - - readGroup().then( ( contacts ) => { - - contacts.sort( (a, b) => { - return b.admin - a.admin; - }) - - let csv = 'Número;Administrador;Status;Nome\n'; - csv += contacts.map( contact => { - const admin = contact.admin ? 'Administrador do grupo' : ''; - const sanitize = `${contact.number};${admin};${contact.status};${contact.name}\n`; - return sanitize.replace(/\,|\'|\"|\“|\”/g,""); - }).join(''); - - saveToDataFile(csv, nameFile || 'grupo'); - }); - -} - -export async function preview(){ - - const name = nameGroup(); - const created = dateCreatedGroup(); - - - readGroup().then( ( contacts ) => { - - contacts.sort( (a, b) => { - return b.admin - a.admin; - }) - - let html = `${name}${style}

${name} (${contacts.length} participantes, ${created})

`; - let cards = ''; - let i = 1; - - for( let contact of contacts){ - - cards += card(contact) - if( i % 14 == 0 ){ - html += container(cards); - cards = ''; - } - i++; - - } - - html += container(cards); - - const previewPage = window.open('about:blank'); - previewPage.document.write(html); - - }); -} - -export function contactsToClipboard(){ - const contacts = readListParticipants(); - copyToClipboard(contacts); - -} \ No newline at end of file diff --git a/src/js/models/setButtons.js b/src/js/models/setButtons.js deleted file mode 100644 index a542d80..0000000 --- a/src/js/models/setButtons.js +++ /dev/null @@ -1,134 +0,0 @@ -import { saveCsv, preview, contactsToClipboard } from './handle.js'; - -const btnCopy = ` `; -const btnPrint = ` `; -const BREAK = 'add-zappull-break'; - -const divBtnCSV = document.createElement("div") -divBtnCSV.setAttribute('id',"btnDown") -divBtnCSV.setAttribute('style',"display: flex; height: 24px") -divBtnCSV.addEventListener("click", saveCsv ); -divBtnCSV.innerHTML = ` `; - -const divBtnPrint = document.createElement("div") -divBtnPrint.setAttribute('id',"btnPrt") -divBtnPrint.setAttribute('style',"display: flex; height: 24px") -divBtnPrint.addEventListener("click", preview); -divBtnPrint.innerHTML = ` `; - - -const setButtons = setInterval( () => { - - if(!document.getElementById(BREAK)){ - const btnMais = document.querySelectorAll('._2nY6U._3A-iD'); - const content = btnMais.length > 0 ? btnMais[btnMais.length - 1] : null; - - if(content){ - const [, containerBtn] = content.childNodes; - const [containerMais] = containerBtn.childNodes; - const [txtMais] = containerMais.childNodes; - const text = String(txtMais.textContent || ''); - - - if(text.match(/mais/g) & 1==2){ - containerBtn.click(); - - let i = 0; - let scrollDow = setInterval(()=>{ - // classe do container dos contatos para rolar - let box = document.querySelector('.KPJpj'); - - i++; - const height = i * 7500 - - if( box && box.scrollTo ){ - // box.scrollTo({top: height, behavior: 'smooth'}); - } - - if (!box || i === 3){ - // containerDadosGrupo.appendChild(divBtnPrint) - clearInterval(scrollDow); - } - - }, 1500); - } - } - - // classe do container Dados do grupo - const containerDadosGrupo = document.querySelector('._1FrBz'); - - if(containerDadosGrupo){ - - if( containerDadosGrupo.innerHTML && containerDadosGrupo.innerHTML === 'Dados do contato') return; - - const ctlBreak = document.createElement("div") - ctlBreak.setAttribute("id", BREAK); - containerDadosGrupo.appendChild(ctlBreak) - - containerDadosGrupo.setAttribute("style", "display: flex; gap: 8px;"); - - //clearInterval(getElement) - - // controlar a quantidade de inscritos no grupo - const [subscribs] = document.querySelectorAll('.i5tg98hk.f9ovudaz.przvwfww.gx1rr48f.shdiholb.phqmzxqs.gtscxtjd.ajgl1lbb.thr4l2wc.cc8mgx9x.eta5aym1.d9802myq.e4xiuwjv'); - const [linkSeeAll] = document.querySelectorAll('.i5tg98hk.f9ovudaz.przvwfww.ddw6s8x9.shdiholb.phqmzxqs.pm5hny62.ajgl1lbb.thr4l2wc.cc8mgx9x.eta5aym1.d9802myq.e4xiuwjv.q1n4p668.ln8gz9je.p357zi0d.gndfcl4n.os03hap6'); - - try { - const countSubscrib = + subscribs.innerText.replace(/\D/g, ''); - - if(countSubscrib < 19){ - containerDadosGrupo.appendChild(divBtnPrint) - containerDadosGrupo.appendChild(divBtnCSV) - }else{ - linkSeeAll.click(); - } - - } catch (error) { - console.log({error}); - } - - } - } - - // classe do container que guarda os nome do grupo e os participantes - const wrapper_participantes = document.querySelector('._3e6xi'); - - if( wrapper_participantes && !document.getElementById('btnCopy')){ - - const text = wrapper_participantes.innerHTML; - if(text === 'online' || text === 'clique aqui para dados do contato') - return; - - if(wrapper_participantes){ - // clearInterval(getElement) - - const button = document.createElement("div") - button.setAttribute('id',"btnCopy") - button.setAttribute('style',"display: flex; height: 18px") - button.addEventListener("click", contactsToClipboard ) - button.innerHTML = `${btnCopy}`; - wrapper_participantes.appendChild(button); - - // const div = wrapper_participantes.firstChild; - // div.appendChild(button); - - } - } - - // modal - const header = document.querySelector('header.-bGGW'); - if(header && !document.getElementById('btnPrtModal')){ - const button = document.createElement("div") - button.setAttribute('id',"btnPrtModal") - button.setAttribute('style',"display: flex; height: 24px; margin:0 5px 0 -65px; cursor: pointer") - button.addEventListener("click", preview); - button.innerHTML = `${btnPrint}`; - header.appendChild(button); - header.appendChild(divBtnCSV); - } - - -}, 2000); - -export default setButtons; - diff --git a/src/js/models/template.js b/src/js/models/template.js deleted file mode 100644 index 18f4965..0000000 --- a/src/js/models/template.js +++ /dev/null @@ -1,51 +0,0 @@ -export function card( contact ){ - - const url = contact.avatar - ? contact.avatar - : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAYAAACLz2ctAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAEKZJREFUeJztnXuQHNV1xr9zZ2Z3Z7UIFIRjZPGIEiQRmWAw5hEhC0m2oVyOKRvxsI0ghrKqbCzHy+72zOyszE1pZ3dmdlWSvQGnKJPwclnW8igXocCAIegBwaR4xQEkIyOZ9yO8tNrHzPQ9+WM3ZYrQd2Z3Z25P99zfv/d099c939zuvn3uuYDFYrFYLBaLxWKxWCwWi8VisVgsFovFYrFYLBaLxWKxWCwWi8VisVgsFoslaJDfAoJAe3t7vKWl5TMR110KYAkLsYCZ5xAwFwAY+ICIDoH5FWLey8Bzo8Xi01u2bBnzWXrdYw3oQY/jLFHARUKINcx8JoDmae5iAsCjAH6jhNje39+/t/oqg4814IfYsGFD8+GtrZcxcAWAM6u5b2J+FMAN0dbWW6SUhWruO8hYAwKQUraUxse/y8wdAD5Vy2Mx8LIABt8fHf3noaGhiVoeKwg0vAF7ksnVzHwtgKWGD/0CEW3ozWbvNXzcuqJhDeg4zmExIX4K5m/5qYOAm6Px+FVSyhE/dfhFQxqwu6vrMyTELwEs9lvLFM8L4KJNudx/+S3ENA1nwJ5k8jxmvg3AnBls7gLYD2AviN5m5lEAIKJWMM8HsATAcQAiM9j3CBFd0JvN3j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UAFLzamfkHUsrqTBmdJXVhwCZgLSbLnn08zDf2DgzsM6co2GSz2RfAfLMmZF5xdPQCY4I01IUBmegybTOw1ZiYkCCItkI3Tkq0zpwab3w3YLqj4zgAn/cMYL7HrjI0fTblcv8N4H5NyKp0Ol1Jcm9N8d2AHIlcqtNBQvzYoJxQUebaCZRK3zImxlOEz5AQum+Yr0VbWh4wJiZk7HnhhV8DeFMTov1+bAJfDSg7Oz8BZs+phwzcFsLUemMMDw+7YL5DE3Ky3/NHfDVgMRpdBc1gOCs1bFBOKCEhdNdQFGOxlcbEfJwAPw/OzKs0zW82z5ljB55nyZ59+x4GoPvqsdqUlo/DVwOS/uR32tvv7BkeHnYBeP+RmRvTgPKHPzwCmrQrIrK9X5Vg/bVcKqWca0zMR/DNgG48vkTXTkDoqoH6BRNpr2VxdHSxKS0fxTcDKtfVnXTxjXfeecqYmJAzMjLyBPTTOLWdQS3x7xmQaKmm9cD111+vy+61TIOhoaEJAC95tZMQDWhA/b/uD8ZUNA7eyRzMDWnAoz1bmK0Bq43mmrKPC/eUqy9SO4jawB7JGkSf7nEcm3pfXZZpphD6to6KfwZk1r36n81EZxvTYvHNgH7egoO6elEYaUgD1kVKuAVAgxrQ1Nq8lvK0+HVg3/MBLY2NNaDFV/x7CwZsprPFYrFYLBaLxWKxWCwWi8VisVgsFovFYrFYLBaLxWKxWCwWi8VisVgsFovFEkD+F1geiAtPdrEgAAAAAElFTkSuQmCC' - - const admin = contact.admin ? `( Administrador )` : ''; - - return `
- -
-

${contact.number}${admin}

-

${contact.name}

-

${contact.status}

-
-
`; -} - -export function container(content){ - return `
${content}
`; -} - - -export const style = `` \ No newline at end of file diff --git a/src/js/models/user.js b/src/js/models/user.js deleted file mode 100644 index 446e01c..0000000 --- a/src/js/models/user.js +++ /dev/null @@ -1,13 +0,0 @@ -class User { - constructor(name) { - this.name = name; - } - static new(props) { - return new this(props.name); - } - greet() { - return `Hello, I'm ${this.name}!`; - } -} - -export default User; diff --git a/src/js/models/utils.js b/src/js/models/utils.js deleted file mode 100644 index 7e406c9..0000000 --- a/src/js/models/utils.js +++ /dev/null @@ -1,109 +0,0 @@ -export function setHeight(size, filter = '.ldL67._1bLj8'){ - - return new Promise( (resolve) => { - //div aside direta - const containerHack = document.querySelector(filter); - - if(containerHack) { - - containerHack.style.height = size; - const check = setInterval( () => { - - if(containerHack.style.height !== size){ - clearInterval(check); - resolve('ok'); - } - - }, 500); - } - - }); -} - -export function copyToClipboard(text) { - - navigator.clipboard.writeText(text) - .then(function() { - alert(' Os participantes do grupo\n foram copiados para área de transferência com sucesso!\n :-) izidorio@bento.dev.br') - }, function(err) { - alert('Não foi possível copiar os contatos para a área de transferência seu navegador não tem suporte a este recurso. :(') - console.error('Async: Could not copy text: ', err); - }); -} - -export function saveToDataFile(text, fileName){ - - const data = new TextEncoder('utf-8').encode(text); - const blob = new Blob(['\uFEFF', data], { type: 'text/csv;charset=utf-8' }); - - const a = document.createElement("a"); - const url = URL.createObjectURL(blob); - - a.href = url; - a.download = `${fileName}.csv`; - document.body.appendChild(a); - a.click(); - - setTimeout(function() { - document.body.removeChild(a); - window.URL.revokeObjectURL(url); - }, 0); - -} - - -async function filterNumbers(payload){ - const numbers = []; - - for (let item of payload){ - try { - const number = item.number.replace(/\D/g,'') - if(number !== '') numbers.push(number); - - } catch (error) { - console.log({error}); - } - } - - return numbers; - -} - -const USER = ''; -const PASS = ''; -const URL_API = `https://portabilidadecelular.com/painel/consulta_numero_json.php?user=${USER}&pass=${PASS}&numeros=`; -const options = { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - mode: "no-cors" -} -export async function addOperatorToNumbers(payload){ - - const numbers = await filterNumbers(payload) - - console.log({numbers}); - console.log(encodeURI(`${URL_API}[${numbers}]`)); - - fetch(encodeURI(`${URL_API}[${numbers}]`), options) - .then(function(response) { - var contentType = response.headers.get("content-type"); - console.log(response); - if(contentType && contentType.indexOf("application/json") !== -1) { - return response.json().then(function(json) { - // process your JSON further - console.log(json); - }); - } else { - console.log("Oops, we haven't got JSON!"); - } - }) - .catch(function(error) { - console.log(error); - }); - - -} - diff --git a/src/modules/handle.js b/src/modules/handle.js new file mode 100644 index 0000000..18d479d --- /dev/null +++ b/src/modules/handle.js @@ -0,0 +1,58 @@ +import { readGroup, dateCreatedGroup, nameGroup, readListParticipants } from "./scraping.js"; +import { saveToDataFile, copyToClipboard } from "./utils.js"; +import { style, card, container } from "./template.js"; + +export async function saveCsv() { + const nameFile = nameGroup(); + + readGroup().then((contacts) => { + contacts.sort((a, b) => { + return b.admin - a.admin; + }); + + let csv = "Número;Administrador;Status;Nome\n"; + csv += contacts + .map((contact) => { + const admin = contact.admin ? "Administrador do grupo" : ""; + const sanitize = `${contact.number};${admin};${contact.status};${contact.name}\n`; + return sanitize.replace(/\,|\'|\"|\“|\”/g, ""); + }) + .join(""); + + saveToDataFile(csv, nameFile || "grupo"); + }); +} + +export async function preview() { + const name = nameGroup(); + const created = dateCreatedGroup(); + + readGroup().then((contacts) => { + contacts.sort((a, b) => { + return b.admin - a.admin; + }); + + let html = `${name}${style}

${name} (${contacts.length} participantes, ${created})

`; + let cards = ""; + let i = 1; + + for (let contact of contacts) { + cards += card(contact); + if (i % 14 == 0) { + html += container(cards); + cards = ""; + } + i++; + } + + html += container(cards); + + const previewPage = window.open("about:blank"); + previewPage.document.write(html); + }); +} + +export function contactsToClipboard() { + const contacts = readListParticipants(); + copyToClipboard(contacts); +} diff --git a/src/modules/index.js b/src/modules/index.js new file mode 100644 index 0000000..b08257c --- /dev/null +++ b/src/modules/index.js @@ -0,0 +1,3 @@ +// export * from "./handle.js"; +// export * from "./parse.js"; +export * from "./config.js"; diff --git a/src/modules/main.js b/src/modules/main.js new file mode 100644 index 0000000..6ee1018 --- /dev/null +++ b/src/modules/main.js @@ -0,0 +1,133 @@ +import { saveCsv, preview, contactsToClipboard } from "./handle.js"; + +const btnCopy = ` `; +const btnPrint = ` `; +const BREAK = "add-zappull-break"; + +const divBtnCSV = document.createElement("div"); +divBtnCSV.setAttribute("id", "btnDown"); +divBtnCSV.setAttribute("style", "display: flex; height: 24px; cursor: pointer"); +divBtnCSV.innerHTML = ` `; +divBtnCSV.addEventListener("click", saveCsv); + +const divBtnPrint = document.createElement("div"); +divBtnPrint.setAttribute("id", "btnPrt"); +divBtnPrint.setAttribute("style", "display: flex; height: 24px"); +divBtnPrint.innerHTML = ` `; +divBtnPrint.addEventListener("click", preview); + +const setButtons = setInterval(() => { + if (!document.getElementById(BREAK)) { + const btnMais = document.querySelectorAll("._2nY6U._3A-iD"); + const content = btnMais.length > 0 ? btnMais[btnMais.length - 1] : null; + + if (content) { + const [, containerBtn] = content.childNodes; + const [containerMais] = containerBtn.childNodes; + const [txtMais] = containerMais.childNodes; + const text = String(txtMais.textContent || ""); + + if (text.match(/mais/g) & (1 == 2)) { + containerBtn.click(); + + let i = 0; + let scrollDow = setInterval(() => { + // classe do container dos contatos para rolar + let box = document.querySelector(".KPJpj"); + + i++; + const height = i * 7500; + + if (box && box.scrollTo) { + // box.scrollTo({top: height, behavior: 'smooth'}); + } + + if (!box || i === 3) { + // containerDadosGrupo.appendChild(divBtnPrint) + clearInterval(scrollDow); + } + }, 1500); + } + } + + // classe do container Dados do grupo + const containerDadosGrupo = document.querySelector("._1FrBz"); + + if (containerDadosGrupo) { + if (containerDadosGrupo.innerHTML && containerDadosGrupo.innerHTML === "Dados do contato") + return; + + const ctlBreak = document.createElement("div"); + ctlBreak.setAttribute("id", BREAK); + containerDadosGrupo.appendChild(ctlBreak); + + containerDadosGrupo.setAttribute("style", "display: flex; gap: 8px;"); + + //clearInterval(getElement) + + // controlar a quantidade de inscritos no grupo + const [subscribs] = document.querySelectorAll( + ".i5tg98hk.f9ovudaz.przvwfww.gx1rr48f.shdiholb.phqmzxqs.gtscxtjd.ajgl1lbb.thr4l2wc.cc8mgx9x.eta5aym1.d9802myq.e4xiuwjv" + ); + const [linkSeeAll] = document.querySelectorAll( + ".i5tg98hk.f9ovudaz.przvwfww.ddw6s8x9.shdiholb.phqmzxqs.pm5hny62.ajgl1lbb.thr4l2wc.cc8mgx9x.eta5aym1.d9802myq.e4xiuwjv.q1n4p668.ln8gz9je.p357zi0d.gndfcl4n.os03hap6" + ); + + try { + const countSubscrib = +subscribs.innerText.replace(/\D/g, ""); + + if (countSubscrib < 19) { + containerDadosGrupo.appendChild(divBtnPrint); + containerDadosGrupo.appendChild(divBtnCSV); + } else { + linkSeeAll.click(); + } + } catch (error) { + console.log({ error }); + } + } + } + + // classe do container que guarda os nome do grupo e os participantes + const wrapper_participantes = document.querySelector( + "div[data-testid='chat-subtitle']" + ).firstChild; + + if (wrapper_participantes && !document.getElementById("btnCopy")) { + const text = wrapper_participantes.innerHTML; + + if (text === "online" || text === "clique para dados do grupo") return; + + if (wrapper_participantes) { + // clearInterval(getElement) + + const button = document.createElement("div"); + button.setAttribute("id", "btnCopy"); + button.setAttribute("style", "display: flex; height: 18px"); + button.innerHTML = `${btnCopy}`; + button.addEventListener("click", contactsToClipboard); + wrapper_participantes.appendChild(button); + + // const div = wrapper_participantes.firstChild; + // div.appendChild(button); + } + } + + // modal + const header = document.querySelector("header.-bGGW"); + if (header && !document.getElementById("btnPrtModal")) { + const button = document.createElement("div"); + button.setAttribute("id", "btnPrtModal"); + button.setAttribute( + "style", + "display: flex; height: 24px; margin:0 5px 0 -65px; cursor: pointer" + ); + button.innerHTML = `${btnPrint}`; + + button.addEventListener("click", preview); + header.appendChild(button); + header.appendChild(divBtnCSV); + } +}, 2000); + +export default setButtons; diff --git a/src/js/models/scraping.js b/src/modules/scraping.js similarity index 87% rename from src/js/models/scraping.js rename to src/modules/scraping.js index ace64d6..f1ab11f 100644 --- a/src/js/models/scraping.js +++ b/src/modules/scraping.js @@ -33,15 +33,18 @@ export function getTotalMembers() { } export async function readGroup() { - //g6kkip0l p357zi0d f8m0rgwh ppled2lx tkdu00h0 gfz4du6o r7fjleex jv8uhy2r lhggkp7q qq0sjtgm ln8gz9je tm2tP copyable-area - const WRAPPER_SUBSCRIBS = ".ln8gz9je.tm2tP.copyable-area"; + //g6kkip0l p357zi0d f8m0rgwh ppled2lx tkdu00h0 gfz4du6o r7fjleex jv8uhy2r lhggkp7q qq0sjtgm ln8gz9je _3cjY2 copyable-area + + // div que envolve o avatar e os dados dos participantes do grupo + const WRAPPER_SUBSCRIBS = "._3cjY2.copyable-area"; await setHeight("9999999999px", WRAPPER_SUBSCRIBS); return new Promise(async (resolve) => { setTimeout(() => { + const box = document.querySelector("._3YS_f._2A1R8"); + // div que envolve o avatar e os dados dos participantes do grupo - const box = document.querySelector(WRAPPER_SUBSCRIBS); - let elements = box.querySelectorAll("._2nY6U"); + let elements = box.querySelectorAll("._199zF._3j691"); let contacts = []; @@ -98,7 +101,9 @@ export async function readGroup() { export function readListParticipants() { // div com a lista de números/nomes dos participantes do grupo try { - const classContainerParticipantes = document.querySelector("._3e6xi"); + const classContainerParticipantes = document.querySelector( + "div[data-testid='chat-subtitle']" + ).firstChild; let title = classContainerParticipantes.textContent.replace(/,\s/gi, "\n"); title = title.replace(/\+55\s|\+|-/gi, ""); return title; diff --git a/src/modules/template.js b/src/modules/template.js new file mode 100644 index 0000000..5adb246 --- /dev/null +++ b/src/modules/template.js @@ -0,0 +1,49 @@ +export function card(contact) { + const url = contact.avatar + ? contact.avatar + : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAYAAACLz2ctAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAEKZJREFUeJztnXuQHNV1xr9zZ2Z3Z7UIFIRjZPGIEiQRmWAw5hEhC0m2oVyOKRvxsI0ghrKqbCzHy+72zOyszE1pZ3dmdlWSvQGnKJPwclnW8igXocCAIegBwaR4xQEkIyOZ9yO8tNrHzPQ9+WM3ZYrQd2Z3Z25P99zfv/d099c939zuvn3uuYDFYrFYLBaLxWKxWCwWi8VisVgsFovFYrFYLBaL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8lvK0+HVg3/MBLY2NNaDFV/x7CwZsprPFYrFYLBaLxWKxWCwWi8VisVgsFovFYrFYLBaLxWKxWCwWi8VisVgsFovFEkD+F1geiAtPdrEgAAAAAElFTkSuQmCC"; + + const admin = contact.admin ? `( Administrador )` : ""; + + return `
+ +
+

${contact.number}${admin}

+

${contact.name}

+

${contact.status}

+
+
`; +} + +export function container(content) { + return `
${content}
`; +} + +export const style = ``; diff --git a/src/modules/utils.js b/src/modules/utils.js new file mode 100644 index 0000000..f358764 --- /dev/null +++ b/src/modules/utils.js @@ -0,0 +1,100 @@ +export function setHeight(size, filter = ".ldL67._1bLj8") { + return new Promise((resolve) => { + //div aside direta + const containerHack = document.querySelector(filter); + + if (containerHack) { + containerHack.style.height = size; + const check = setInterval(() => { + if (containerHack.style.height !== size) { + clearInterval(check); + resolve("ok"); + } + }, 500); + } + }); +} + +export function copyToClipboard(text) { + navigator.clipboard.writeText(text).then( + function () { + alert( + " Os participantes do grupo\n foram copiados para área de transferência com sucesso!\n :-) izidorio@bento.dev.br" + ); + }, + function (err) { + alert( + "Não foi possível copiar os contatos para a área de transferência seu navegador não tem suporte a este recurso. :(" + ); + console.error("Async: Could not copy text: ", err); + } + ); +} + +export function saveToDataFile(text, fileName) { + const data = new TextEncoder("utf-8").encode(text); + const blob = new Blob(["\uFEFF", data], { type: "text/csv;charset=utf-8" }); + + const a = document.createElement("a"); + const url = URL.createObjectURL(blob); + + a.href = url; + a.download = `${fileName}.csv`; + document.body.appendChild(a); + a.click(); + + setTimeout(function () { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); +} + +async function filterNumbers(payload) { + const numbers = []; + + for (let item of payload) { + try { + const number = item.number.replace(/\D/g, ""); + if (number !== "") numbers.push(number); + } catch (error) { + console.log({ error }); + } + } + + return numbers; +} + +const USER = ""; +const PASS = ""; +const URL_API = `https://portabilidadecelular.com/painel/consulta_numero_json.php?user=${USER}&pass=${PASS}&numeros=`; +const options = { + method: "GET", + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + }, + mode: "no-cors", +}; +export async function addOperatorToNumbers(payload) { + const numbers = await filterNumbers(payload); + + console.log({ numbers }); + console.log(encodeURI(`${URL_API}[${numbers}]`)); + + fetch(encodeURI(`${URL_API}[${numbers}]`), options) + .then(function (response) { + var contentType = response.headers.get("content-type"); + console.log(response); + if (contentType && contentType.indexOf("application/json") !== -1) { + return response.json().then(function (json) { + // process your JSON further + console.log(json); + }); + } else { + console.log("Oops, we haven't got JSON!"); + } + }) + .catch(function (error) { + console.log(error); + }); +}