-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
155 lines (126 loc) · 4.77 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//Roda no background do navegador
//Recebe a mensagem do script do popup
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
sendResponse({contentBtn: "Processando..."})
let allSNs = request.sns
inputSN(allSNs)
}
);
//Pega tabela com o registros
function getTable(){
//let tableMain = document.getElementById('grid_1').childNodes[0]
let tableMain = document.querySelector('tbody').childNodes
//let countRegister = tableMain.childNodes
return tableMain
}
//insere os SNS e salva
async function inputSN(allSNs){
loadingAnimation()
const arraySns = allSNs
let updateRegister = getTable()
let totalOfPages = Math.ceil(arraySns.length / updateRegister.length)
for(let i = 0; i < totalOfPages; i++) {
for(let i in arraySns){
if(i < updateRegister.length){
let newUpdateRegister = getTable()
newUpdateRegister[i].dispatchEvent(new MouseEvent ('dblclick', {bubble: true}))
const serialNumber = document.getElementById('serial_fornecedor')
await sleep(3)
serialNumber.value = arraySns[i]
await sleep(3)
saveChange()
await sleep(3)
}
if( i >= updateRegister.length){
const nextBtn = document.querySelector(".fa-forward").click()
arraySns.splice(0, updateRegister.length)
await sleep(2)
break
}
}
}
loadingAnimation(false)
chrome.runtime.sendMessage({newTextContent: "Nova inserção"})
/*
loadingAnimation()
const arraySns = allSNs
let countRegister = getTable()
let totalOfPages = Math.ceil(arraySns.length / countRegister.length)
console.log(totalOfPages)
for(let i = 0; i < totalOfPages; i++) {
//Atualizando a tabela
let countRegister = getTable()
for(let y in arraySns){
if(y <= countRegister.length){
let countRegister = getTable()
countRegister[y].dispatchEvent(new MouseEvent ('dblclick', {bubble: true}))
const serialNumber = document.getElementById('serial_fornecedor')
await sleep(2)
serialNumber.value = arraySns[y]
await sleep(2)
saveChange()
await sleep(2)
}
if (y >= countRegister.length){
let nextBtn = document.querySelector(".fa-forward").click()
arraySns.splice(0, 30)
break;
}
}
}
loadingAnimation(false)
chrome.runtime.sendMessage({newTextContent: "Nova inserção"})
*/
}
//Salva as alterações e troca fecha a pagina
function saveChange(){
setTimeout(() => {
const btnSave = document.querySelector('.disab')
//btnSave.click()
const btnClose = document.querySelectorAll('.fa-times')[2]
btnClose.click()
}, 1000)
}
//Função "Cronometro"
async function sleep(time){
return new Promise(function (resolve, reject){
setTimeout(() => {
resolve()
}, time * 1000)
})
}
// Cria animação de carregamento
function loadingAnimation(isActive = true) {
// Verifica se o parâmetro is active é true. Se sim, inicia a animação
if (isActive == true) {
// Salva body em uma variável, cria uma div #modal-container
const body = document.querySelector('body')
const divModalContainer = document.createElement('div')
divModalContainer.setAttribute('class', 'modal-container')
divModalContainer.setAttribute('id', 'modal-container')
// Cria uma div dentro da #modal-container
const divModal = document.createElement('div')
divModal.setAttribute('class', 'modal')
// Cria h1
const loading = document.createElement('h1')
loading.textContent = 'Carregando resultados'
// Cria span para a moldura o quadro
const loader = document.createElement('span')
loader.setAttribute('class', 'loader')
// Cria ooutro span para preencher o quadro
const innerLoader = document.createElement('span')
innerLoader.setAttribute('class', 'loader-inner')
// Insere um no outro
loader.append(innerLoader)
// Insere a div dentro da div modal, e a div modal na div modal container
divModal.append(loading, loader)
divModalContainer.append(divModal)
body.append(divModalContainer)
}
// Se falso, deleta a div modal-container
if (isActive == false) {
const body = document.querySelector('body')
body.removeChild(document.getElementById('modal-container'))
}
}