-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
83 lines (70 loc) · 2.38 KB
/
Copy pathcontent.js
File metadata and controls
83 lines (70 loc) · 2.38 KB
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
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// 1. Inyectamos el CSS necesario para el pseudo-elemento
const injectStyles = () => {
const style = document.createElement('style');
style.textContent = `
.header-title.is-applying::after {
content: " - Aplicando cupones...";
color: #00a650; /* Color verde Mercado Libre */
font-weight: bold;
font-size: 0.8em;
margin-left: 10px;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
`;
document.head.appendChild(style);
};
function nextPage() {
// 4. Quitamos el mensaje antes de cambiar de página
const title = document.querySelector('.header-title');
if (title) title.classList.remove('is-applying');
var nextPageButton = document.querySelector('.andes-pagination__button--next');
if (nextPageButton.classList.contains("andes-pagination__button--disabled")) {
chrome.runtime.sendMessage({
action: "SHOW_NOTIFICATION",
title: "Mercado Libre | Cupones",
message: "Ya no hay más cupones por aplicar. ¡Disfruta de tu compra!"
});
chrome.runtime.sendMessage({ action: "CLOSE_TAB" });
return;
}
const link = nextPageButton.querySelector('a');
link.href = link.href + "&autoclick=true";
link.click();
}
async function clickAllWithDelay() {
// 2. Activamos el mensaje visual
const title = document.querySelector('.header-title');
if (title) title.classList.add('is-applying');
const timeout = 1000;
const startTime = Date.now();
while (document.querySelectorAll('.andes-button--loud').length === 0) {
if (Date.now() - startTime > timeout) {
nextPage();
return;
}
await delay(500);
}
while (true) {
const elements = document.querySelectorAll('.andes-button--loud');
if (elements.length === 0) break;
for (const el of elements) {
el.click();
await delay(50);
}
await delay(500);
}
nextPage();
}
// 3. Ejecución inicial
injectStyles();
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', clickAllWithDelay);
} else {
clickAllWithDelay();
}