🤖┃Auto-Farm ( V01 )

This commit is contained in:
DarkMode authored and GitHub committed 2025-08-06 02:20:19 -03:00
1 parent c45e3a5ed5
commit 45c7fb7807
1 file changed
+419
+419
View File
@@ -0,0 +1,419 @@
(async () => {
// Configurações globais
const CONFIG = {
START_X: 742,
START_Y: 1148,
PIXELS_PER_LINE: 100,
COLOR_ID: 1,
DELAY: 1000,
THEME: {
primary: '#000000',
secondary: '#111111',
accent: '#222222',
text: '#ffffff',
highlight: '#775ce3',
success: '#00ff00',
error: '#ff0000'
}
};
// Estado do aplicativo
const state = {
running: false,
paintedCount: 0,
charges: { count: 0, max: 80, cooldownMs: 30000 },
userInfo: null,
lastPixel: null,
minimized: false,
menuOpen: false
};
// Funções utilitárias
const sleep = ms => new Promise(r => setTimeout(r, ms));
const fetchAPI = async (url, options = {}) => {
try {
const res = await fetch(url, {
credentials: 'include',
...options
});
return await res.json();
} catch (e) {
console.error('Erro na requisição:', e);
return null;
}
};
// Funções da API
const getRandomPosition = () => ({
x: Math.floor(Math.random() * CONFIG.PIXELS_PER_LINE),
y: Math.floor(Math.random() * CONFIG.PIXELS_PER_LINE)
});
const paintPixel = async (x, y, color) => {
return await fetchAPI(`https://backend.wplace.live/s0/pixel/${CONFIG.START_X}/${CONFIG.START_Y}`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain;charset=UTF-8' },
body: JSON.stringify({ coords: [x, y], colors: [color] })
});
};
const getCharge = async () => {
const data = await fetchAPI('https://backend.wplace.live/me');
if (data) {
state.userInfo = data;
state.charges = {
count: Math.floor(data.charges.count),
max: Math.floor(data.charges.max),
cooldownMs: data.charges.cooldownMs
};
if (state.userInfo.level) {
state.userInfo.level = Math.floor(state.userInfo.level);
}
}
return state.charges;
};
// Lógica principal
const paintLoop = async () => {
while (state.running) {
const { count, cooldownMs } = state.charges;
if (count < 1) {
updateUI(`⌛ Sem cargas. Esperando ${Math.ceil(cooldownMs/1000)}s...`, 'status');
await sleep(cooldownMs);
await getCharge();
continue;
}
const randomPos = getRandomPosition();
const paintResult = await paintPixel(randomPos.x, randomPos.y, CONFIG.COLOR_ID);
if (paintResult?.painted === 1) {
state.paintedCount++;
state.lastPixel = {
x: CONFIG.START_X + randomPos.x,
y: CONFIG.START_Y + randomPos.y,
time: new Date()
};
state.charges.count--;
// Efeito visual
document.getElementById('paintEffect').style.animation = 'pulse 0.5s';
setTimeout(() => {
document.getElementById('paintEffect').style.animation = '';
}, 500);
updateUI(`✅ Pixel pintado!`, 'success');
} else {
updateUI(`❌ Falha ao pintar`, 'error');
}
await sleep(CONFIG.DELAY);
updateStats();
}
};
// Interface do usuário
const createUI = () => {
if (state.menuOpen) return;
state.menuOpen = true;
// Adiciona Font Awesome
const fontAwesome = document.createElement('link');
fontAwesome.rel = 'stylesheet';
fontAwesome.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css';
document.head.appendChild(fontAwesome);
// Adiciona estilos
const style = document.createElement('style');
style.textContent = `
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.7); }
70% { box-shadow: 0 0 0 10px rgba(0, 255, 0, 0); }
100% { box-shadow: 0 0 0 0 rgba(0, 255, 0, 0); }
}
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.wplace-bot-panel {
position: fixed;
top: 20px;
right: 20px;
width: 250px;
background: ${CONFIG.THEME.primary};
border: 1px solid ${CONFIG.THEME.accent};
border-radius: 8px;
padding: 0;
box-shadow: 0 5px 15px rgba(0,0,0,0.5);
z-index: 9999;
font-family: 'Segoe UI', Roboto, sans-serif;
color: ${CONFIG.THEME.text};
animation: slideIn 0.4s ease-out;
overflow: hidden;
}
.wplace-header {
padding: 12px 15px;
background: ${CONFIG.THEME.secondary};
color: ${CONFIG.THEME.highlight};
font-size: 16px;
font-weight: 600;
display: flex;
justify-content: space-between;
align-items: center;
cursor: move;
user-select: none;
}
.wplace-header-title {
display: flex;
align-items: center;
gap: 8px;
}
.wplace-header-controls {
display: flex;
gap: 10px;
}
.wplace-header-btn {
background: none;
border: none;
color: ${CONFIG.THEME.text};
cursor: pointer;
opacity: 0.7;
transition: opacity 0.2s;
}
.wplace-header-btn:hover {
opacity: 1;
}
.wplace-content {
padding: 15px;
display: ${state.minimized ? 'none' : 'block'};
}
.wplace-controls {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.wplace-btn {
flex: 1;
padding: 10px;
border: none;
border-radius: 6px;
font-weight: 600;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: all 0.2s;
}
.wplace-btn:hover {
transform: translateY(-2px);
}
.wplace-btn-primary {
background: ${CONFIG.THEME.accent};
color: white;
}
.wplace-btn-stop {
background: ${CONFIG.THEME.error};
color: white;
}
.wplace-stats {
background: ${CONFIG.THEME.secondary};
padding: 12px;
border-radius: 6px;
margin-bottom: 15px;
}
.wplace-stat-item {
display: flex;
justify-content: space-between;
padding: 6px 0;
font-size: 14px;
}
.wplace-stat-label {
display: flex;
align-items: center;
gap: 6px;
opacity: 0.8;
}
.wplace-status {
padding: 8px;
border-radius: 4px;
text-align: center;
font-size: 13px;
}
.status-default {
background: rgba(255,255,255,0.1);
}
.status-success {
background: rgba(0, 255, 0, 0.1);
color: ${CONFIG.THEME.success};
}
.status-error {
background: rgba(255, 0, 0, 0.1);
color: ${CONFIG.THEME.error};
}
#paintEffect {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
border-radius: 8px;
}
`;
document.head.appendChild(style);
// Cria o painel
const panel = document.createElement('div');
panel.className = 'wplace-bot-panel';
panel.innerHTML = `
<div id="paintEffect"></div>
<div class="wplace-header">
<div class="wplace-header-title">
<i class="fas fa-paint-brush"></i>
<span>WPlace Auto-Farm</span>
</div>
<div class="wplace-header-controls">
<button id="minimizeBtn" class="wplace-header-btn" title="Minimizar">
<i class="fas fa-${state.minimized ? 'expand' : 'minus'}"></i>
</button>
</div>
</div>
<div class="wplace-content">
<div class="wplace-controls">
<button id="toggleBtn" class="wplace-btn wplace-btn-primary">
<i class="fas fa-play"></i>
<span>Iniciar</span>
</button>
</div>
<div class="wplace-stats">
<div id="statsArea">
<div class="wplace-stat-item">
<div class="wplace-stat-label"><i class="fas fa-paint-brush"></i> Carregando...</div>
</div>
</div>
</div>
<div id="statusText" class="wplace-status status-default">
Pronto para começar
</div>
</div>
`;
document.body.appendChild(panel);
// Tornar arrastável
const header = panel.querySelector('.wplace-header');
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
header.onmousedown = dragMouseDown;
function dragMouseDown(e) {
if (e.target.closest('.wplace-header-btn')) return;
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
panel.style.top = (panel.offsetTop - pos2) + "px";
panel.style.left = (panel.offsetLeft - pos1) + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
// Controles
const toggleBtn = panel.querySelector('#toggleBtn');
const minimizeBtn = panel.querySelector('#minimizeBtn');
const statusText = panel.querySelector('#statusText');
const content = panel.querySelector('.wplace-content');
const statsArea = panel.querySelector('#statsArea');
toggleBtn.addEventListener('click', () => {
state.running = !state.running;
if (state.running) {
toggleBtn.innerHTML = `<i class="fas fa-stop"></i> <span>Parar</span>`;
toggleBtn.classList.remove('wplace-btn-primary');
toggleBtn.classList.add('wplace-btn-stop');
updateUI('🚀 Pintura iniciada!', 'success');
paintLoop();
} else {
toggleBtn.innerHTML = `<i class="fas fa-play"></i> <span>Iniciar</span>`;
toggleBtn.classList.add('wplace-btn-primary');
toggleBtn.classList.remove('wplace-btn-stop');
updateUI('⏸️ Pintura pausada', 'default');
}
});
minimizeBtn.addEventListener('click', () => {
state.minimized = !state.minimized;
content.style.display = state.minimized ? 'none' : 'block';
minimizeBtn.innerHTML = `<i class="fas fa-${state.minimized ? 'expand' : 'minus'}"></i>`;
});
// Fechar o painel quando a página for recarregada
window.addEventListener('beforeunload', () => {
state.menuOpen = false;
});
};
// Funções de atualização da UI
window.updateUI = (message, type = 'default') => {
const statusText = document.querySelector('#statusText');
if (statusText) {
statusText.textContent = message;
statusText.className = `wplace-status status-${type}`;
statusText.style.animation = 'none';
void statusText.offsetWidth;
statusText.style.animation = 'slideIn 0.3s ease-out';
}
};
window.updateStats = async () => {
await getCharge();
const statsArea = document.querySelector('#statsArea');
if (statsArea) {
statsArea.innerHTML = `
<div class="wplace-stat-item">
<div class="wplace-stat-label"><i class="fas fa-user"></i> Usuário</div>
<div>${state.userInfo.name}</div>
</div>
<div class="wplace-stat-item">
<div class="wplace-stat-label"><i class="fas fa-paint-brush"></i> Pixels</div>
<div>${state.paintedCount}</div>
</div>
<div class="wplace-stat-item">
<div class="wplace-stat-label"><i class="fas fa-bolt"></i> Cargas</div>
<div>${Math.floor(state.charges.count)}</div>
</div>
<div class="wplace-stat-item">
<div class="wplace-stat-label"><i class="fas fa-star"></i> Level</div>
<div>${state.userInfo?.level || '0'}</div>
</div>
`;
}
};
// Inicialização
createUI();
await getCharge();
updateStats();
console.log('WPlace Bot - Interface carregada com sucesso!');
})();