-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFollow_Mode_user.js
More file actions
169 lines (149 loc) · 6.97 KB
/
Copy pathFollow_Mode_user.js
File metadata and controls
169 lines (149 loc) · 6.97 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(function() {
// Variables que se definirán a partir de chrome.storage.local
let targetFollows = null; // Número total de follows a realizar (aleatorio entre minFollows y maxFollows)
let clickCount = 0;
let followModeActive = false; // Bandera para controlar si el modo está activo
let timeoutId = null; // Referencia al timeout actual
// Variables para los intervalos de tiempo (en milisegundos) que se obtendrán desde storage
let sleepTimeMinValue = null;
let sleepTimeMaxValue = null;
/**
* Función para obtener el primer elemento clickeable que contenga "seguir" o "follow",
* sin distinguir mayúsculas/minúsculas, excluyendo elementos <style> y aquellos que ya hayan
* sido clickeados (por ejemplo, cambiados a "siguiendo" o "following"), y comprobando que sean visibles.
*/
function getPrimerElementoClickeable() {
// Intentar primero con "seguir", pero excluyendo aquellos que contengan "siguiendo"
let xpath = `//*[not(self::style) and
contains(translate(normalize-space(text()), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'seguir')
and not(contains(translate(normalize-space(text()), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'siguiendo'))
]`;
let resultado = document.evaluate(
xpath,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
// Si no se encontró ningún elemento con "seguir", intentar con "follow" excluyendo "following"
if (resultado.snapshotLength === 0) {
xpath = `//*[not(self::style) and
contains(translate(normalize-space(text()), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'follow')
and not(contains(translate(normalize-space(text()), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'following'))
]`;
resultado = document.evaluate(
xpath,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
}
// Recorrer los resultados y devolver el primer elemento clickeable y visible
for (let i = 0; i < resultado.snapshotLength; i++) {
const elemento = resultado.snapshotItem(i);
if (typeof elemento.click === "function" && elemento.offsetParent !== null) {
return elemento;
}
}
return null;
}
// Función recursiva que busca el elemento, hace click y espera antes de la siguiente iteración
function clickYBuscar() {
// Si se ha detenido el modo, no hacer nada
if (!followModeActive) {
console.log("El Follow Mode ha sido detenido.");
return;
}
// Si se alcanzó el número de follows objetivo, se detiene el modo
if (clickCount >= targetFollows) {
console.log(`Se completaron ${targetFollows} follows.`);
followModeActive = false;
return;
}
// Buscar el primer elemento clickeable con el texto "seguir" o "follow"
let elemento = getPrimerElementoClickeable();
if (!elemento) {
console.log("No se encontró ningún elemento clickeable con el texto 'seguir' o 'follow'.");
// Si no se encuentra, esperar el tiempo mínimo (o 1000 ms de respaldo) y reintentar
timeoutId = setTimeout(clickYBuscar, sleepTimeMinValue || 1000);
return;
}
console.log(`Follow #${clickCount + 1} en:`, elemento);
try {
elemento.click();
} catch (error) {
console.error("Error al hacer click en el elemento:", error);
}
clickCount++;
// Calcular un intervalo aleatorio entre sleepTimeMinValue y sleepTimeMaxValue
let intervalo;
if (
sleepTimeMinValue != null &&
sleepTimeMaxValue != null &&
sleepTimeMaxValue > sleepTimeMinValue
) {
intervalo = sleepTimeMinValue + Math.floor(Math.random() * (sleepTimeMaxValue - sleepTimeMinValue));
intervalo = intervalo * 1000;
console.log("intervalo:", intervalo);
} else {
// Valor de respaldo en caso de que no se hayan configurado correctamente (1-2 segundos)
intervalo = 1000 + Math.floor(Math.random() * 1000);
}
timeoutId = setTimeout(clickYBuscar, intervalo);
}
// Listener para recibir mensajes desde el background
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "startFollow") {
console.log("Mensaje recibido: iniciar Follow Mode.");
// Obtener los valores sleepTimeMin, sleepTimeMax, followCountMin y followCountMax desde storage
chrome.storage.local.get(
["sleepTimeMin", "sleepTimeMax", "followCountMin", "followCountMax"],
(result) => {
if (
result.sleepTimeMin == null ||
result.sleepTimeMax == null ||
result.followCountMin == null ||
result.followCountMax == null
) {
console.error("Faltan valores en storage: se requieren 'sleepTimeMin', 'sleepTimeMax', 'followCountMin' y 'followCountMax'.");
sendResponse({ status: "error", details: "Faltan valores en storage." });
return;
}
sleepTimeMinValue = parseInt(result.sleepTimeMin, 10);
sleepTimeMaxValue = parseInt(result.sleepTimeMax, 10);
const minFollows = parseInt(result.followCountMin, 10);
const maxFollows = parseInt(result.followCountMax, 10);
if (isNaN(sleepTimeMinValue) || isNaN(sleepTimeMaxValue)) {
console.error("Los valores de tiempo en storage no son válidos.");
sendResponse({ status: "error", details: "Valores de tiempo no válidos." });
return;
}
if (isNaN(minFollows) || isNaN(maxFollows)) {
console.error("Los valores de follow count en storage no son válidos.");
sendResponse({ status: "error", details: "Valores de follow count no válidos." });
return;
}
console.log("Valores de tiempo obtenidos: sleepTimeMin =", sleepTimeMinValue, "ms, sleepTimeMax =", sleepTimeMaxValue, "ms.");
console.log("Valores de follows obtenidos: followCountMin =", minFollows, ", followCountMax =", maxFollows);
// Calcular el número objetivo de follows (aleatorio entre minFollows y maxFollows)
targetFollows = minFollows + Math.floor(Math.random() * (maxFollows - minFollows + 1));
console.log(`Target Follows: ${targetFollows}`);
// Reiniciar contador y activar el modo
clickCount = 0;
followModeActive = true;
clickYBuscar();
sendResponse({ status: "Follow mode started" });
}
);
return true; // Para responder de forma asíncrona
} else if (message.action === "stopFollow") {
console.log("Mensaje recibido: detener Follow Mode.");
followModeActive = false;
if (timeoutId) {
clearTimeout(timeoutId);
}
sendResponse({ status: "Follow mode stopped" });
}
});
})();