// ==UserScript==
// @name CF Legends: Auto-farm Referral
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Automates cflegends inviting process with instant refresh on email timeout
// @author Chisato-Chan
// @match *://*.playcfl.com/*
// @match *://*.intlgame.com/*
// @run-at document-start
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
// --- CONFIGURATION ---
const BASE_EMAIL = "xxxxx"; //your base email example: test@gmail.com but without @gmail.com
const EMAIL_DOMAIN = "xxxx"; //email domain
const USE_RANDOM_TAG = true; // true = random numbers from the email. if false = index number
const STARTING_INDEX = 1; // starting index if USE_RANDOM_TAG is false
const FINAL_TIMEOUT = 30; // timer after signing up before wiping data
const EMAIL_POLL_TIMEOUT = 30; // timer to wait for email code
// --- SERVER URLS --- (No need to modify)
const SERVER_BASE = "http://localhost:5000";
const PYTHON_SERVER_URL = `${SERVER_BASE}/get-code`;
const LOG_URL = `${SERVER_BASE}/log-success`;
const ALARM_URL = `${SERVER_BASE}/trigger-alarm`;
const statusBox = document.createElement('div');
statusBox.id = 'cfl-status-box';
statusBox.style.cssText = 'position:fixed; top:10px; right:10px; background:rgba(0,0,0,0.8); color:#00ff00; padding:10px; border-radius:5px; z-index:999999; font-family:monospace; font-size:12px; text-align:right; pointer-events:none; transition: background 0.2s;';
let wakeLock = null;
let alarmTriggered = false;
let emailTag;
let savedIndex = GM_getValue("cfl_loop_index", 0);
if (USE_RANDOM_TAG) {
emailTag = Math.floor(1000000000 + Math.random() * 9000000000);
} else {
if (STARTING_INDEX > savedIndex) {
GM_setValue("cfl_loop_index", STARTING_INDEX);
savedIndex = STARTING_INDEX;
}
emailTag = savedIndex;
}
const EMAIL_TO_USE = `${BASE_EMAIL}+${emailTag}${EMAIL_DOMAIN}`;
function ensureUI() {
if (document.body && !document.getElementById('cfl-status-box')) {
document.body.appendChild(statusBox);
}
}
setInterval(ensureUI, 500);
function updateStatus(msg, color='#00ff00') {
ensureUI();
if (!alarmTriggered) {
statusBox.style.background = 'rgba(0,0,0,0.8)';
}
statusBox.innerHTML = `
🤖 CFL BOT RUNNING<br>
<span style="color:#aaa; font-size:10px;">phcorner.org | Chisato-Chan</span><br>
${EMAIL_TO_USE}<br>
<span style="color:${color}">${msg}</span>
`;
console.log(`[phcorner.org | Chisato-Chan] ${msg.replace(/<[^>]*>?/gm, '')}`);
}
updateStatus("🚀 INITIALIZING...");
function triggerServerAlarm() {
if (alarmTriggered) return;
alarmTriggered = true;
updateStatus("🚨 CAPTCHA DETECTED! 🚨", "white");
let toggle = true;
setInterval(() => {
if (toggle) {
statusBox.style.background = 'red';
statusBox.style.border = '2px solid white';
} else {
statusBox.style.background = 'blue';
statusBox.style.border = '2px solid yellow';
}
toggle = !toggle;
}, 300);
if (wakeLock) wakeLock.release();
GM_xmlhttpRequest({ method: "POST", url: ALARM_URL });
setInterval(() => {
GM_xmlhttpRequest({ method: "POST", url: ALARM_URL });
}, 5000);
// 🔄 AUTO REFRESH CURRENT PAGE AFTER 10 SECONDS
setTimeout(() => {
location.reload();
}, 10000);
}
function reportSuccessToDashboard() {
let currentUrl = window.location.href;
let refCode = "Unknown";
try { if (currentUrl.includes("code=")) refCode = currentUrl.split("code=")[1].split("&")[0]; } catch(e) {}
GM_xmlhttpRequest({
method: "POST", url: LOG_URL, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: "code=" + refCode
});
}
async function requestWakeLock() {
try { if ('wakeLock' in navigator) wakeLock = await navigator.wakeLock.request('screen'); } catch (err) {}
}
function injectPopupKiller() {
const script = document.createElement('script');
script.textContent = `
(function() {
window.alert = function(msg) {
msg = String(msg || "");
if (msg.includes("Invitation accepted")) {
localStorage.setItem('cfl_bot_status', 'SUCCESS: Invitation Accepted');
return true;
}
if (msg.includes("already been invited")) {
localStorage.setItem('cfl_bot_status', 'SUCCESS: Already Invited');
return true;
}
if (msg.includes("busy") || msg.includes("Network") || msg.includes("Confirm Passing")) return true;
return true;
};
window.confirm = window.alert;
})();
`;
(document.head || document.documentElement).appendChild(script);
script.remove();
}
injectPopupKiller();
function wipeAndReload() {
GM_setValue("cfl_loop_index", savedIndex + 1);
localStorage.removeItem('cfl_final_timer_start');
setTimeout(() => {
updateStatus("🧹 WIPING Data...", "orange");
localStorage.clear();
sessionStorage.clear();
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
const eqPos = cookie.indexOf("=");
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=" + window.location.hostname;
}
window.location.reload();
}, 1000);
}
function humanClick(element) {
if (!element) return;
element.scrollIntoView({behavior: "smooth", block: "center"});
element.click();
}
function typeValue(element, value) {
if (!element) return;
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
nativeInputValueSetter.call(element, value);
element.dispatchEvent(new Event('input', { bubbles: true }));
element.dispatchEvent(new Event('change', { bubbles: true }));
}
let scriptState = 0;
let isPolling = false;
let regionTimer = 0;
let emailPollStartTime = 0;
requestWakeLock();
setInterval(() => {
if (alarmTriggered) return;
if (!wakeLock) requestWakeLock();
const timerStart = localStorage.getItem('cfl_final_timer_start');
if (timerStart) {
const elapsed = (Date.now() - parseInt(timerStart)) / 1000;
if (elapsed < FINAL_TIMEOUT) {
updateStatus(`⏳ Final Timer: ${Math.floor(elapsed)}s`, "cyan");
} else {
updateStatus("⚠️ TIMEOUT! Resetting.", "red");
wipeAndReload();
return;
}
}
const botStatus = localStorage.getItem('cfl_bot_status');
if (botStatus) {
updateStatus(`🏆 ${botStatus}`, "#00ffff");
if (botStatus.includes("Invitation Accepted")) {
reportSuccessToDashboard();
}
localStorage.removeItem('cfl_bot_status');
setTimeout(wipeAndReload, 1500);
return;
}
const successText = document.evaluate("//div[contains(text(), 'Draw(') or contains(text(), 'Log in to draw')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (successText) {
updateStatus("🏆 LOGIN SUCCESS (No Invite)", "#00ffff");
setTimeout(wipeAndReload, 1500);
return;
}
// Region & continue logic
if (scriptState === 4) {
const skipBtn = document.querySelector('button[name="confirm"]') || document.evaluate("//button[contains(., 'Skip')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (skipBtn) { humanClick(skipBtn); localStorage.setItem('cfl_final_timer_start', Date.now()); scriptState = 5; return; }
}
if (scriptState === 3) {
const continueBtn = document.evaluate("//button[contains(., 'Continue')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (continueBtn && !continueBtn.disabled) { humanClick(continueBtn); localStorage.setItem('cfl_final_timer_start', Date.now()); scriptState = 4; return; }
}
if (scriptState === 28) {
updateStatus("⚡ Unlocking Continue...", "orange");
const codeInput = document.querySelector('input[placeholder="Verification code"]');
const emailInput = document.getElementById("registerForm_account");
if (codeInput) { codeInput.focus(); codeInput.click(); }
if (emailInput) { emailInput.focus(); emailInput.click(); }
setTimeout(() => { scriptState = 3; }, 800);
return;
}
if (scriptState === 2) {
const checkbox = document.querySelector('.infinite-checkbox-input[type="checkbox"]');
if (checkbox) { if (!checkbox.checked) checkbox.click(); scriptState = 28; return; }
else { const continueBtn = document.evaluate("//button[contains(., 'Continue')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if(continueBtn) scriptState = 3; }
}
if (scriptState === 25) {
const regionBox = document.querySelector('.infinite-select-selector');
const regionText = document.querySelector('.infinite-select-selection-item');
if (regionBox && regionText) {
const currentRegion = regionText.innerText.trim() || regionText.title;
if (currentRegion === "Philippines") { updateStatus("✅ Region Correct"); scriptState = 2; return; }
else {
if (regionTimer === 0) { updateStatus(`Opening Region...`, "orange"); regionBox.click(); regionTimer = Date.now(); return; }
if (Date.now() - regionTimer < 1000) { updateStatus("⌛ Waiting for dropdown...", "yellow"); return; }
const searchInput = document.querySelector('#area');
if (searchInput) { updateStatus("⌨️ Typing Philippines...", "blue"); typeValue(searchInput, "Philippines"); setTimeout(() => { const ev = new KeyboardEvent('keydown', { bubbles: true, keyCode: 13, key: "Enter" }); searchInput.dispatchEvent(ev); regionTimer = 0; }, 500); } else { regionTimer = 0; }
}
} else { scriptState = 2; }
return;
}
if (scriptState === 1) {
if (emailPollStartTime === 0) emailPollStartTime = Date.now();
const waitTime = (Date.now() - emailPollStartTime) / 1000;
// ✅ INSTANT REFRESH ON EMAIL TIMEOUT (no alarm)
if (waitTime > EMAIL_POLL_TIMEOUT) {
updateStatus("⏳ Email timeout! Refreshing page...", "red");
setTimeout(() => { location.reload(); }, 0);
return;
}
if (!isPolling) {
isPolling = true;
updateStatus(`📡 Waiting for email (${Math.floor(waitTime)}s)...`);
GM_xmlhttpRequest({
method: "GET", url: PYTHON_SERVER_URL, onload: function(response) {
try {
const data = JSON.parse(response.responseText);
if (data.status === "found" && data.code) {
updateStatus("✅ CODE: " + data.code, "cyan");
const codeInput = document.querySelector('input[placeholder="Verification code"]');
if (codeInput) { typeValue(codeInput, data.code); scriptState = 25; emailPollStartTime = 0; }
}
} catch (e) { }
setTimeout(() => { isPolling = false; }, 3000);
}, onerror: function() { setTimeout(() => { isPolling = false; }, 3000); }
});
}
}
// Initial registration logic
if (scriptState === 0) {
const emailField = document.getElementById("registerForm_account");
const getCodeBtn = document.evaluate("//button[contains(., 'Get code')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (emailField && getCodeBtn) {
if (emailField.value === EMAIL_TO_USE && getCodeBtn.disabled) { updateStatus("⚡ Enabling Button...", "orange"); typeValue(emailField, EMAIL_TO_USE); return; }
if (emailField.value === EMAIL_TO_USE && !getCodeBtn.disabled) {
if (getCodeBtn.dataset.clicked) return;
getCodeBtn.dataset.clicked = "true";
updateStatus("⏳ Waiting 2s...", "yellow");
setTimeout(() => { updateStatus("🖱️ CLICKING", "blue"); getCodeBtn.click(); scriptState = 1; setTimeout(() => { if(scriptState === 0) delete getCodeBtn.dataset.clicked; }, 5000); }, 2000);
}
}
}
const emailInput = document.getElementById("registerForm_account");
if (scriptState === 0 && emailInput && emailInput.value === "") typeValue(emailInput, EMAIL_TO_USE);
const registerBtn = document.evaluate("//span[contains(text(), 'Register for free')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (registerBtn && !document.getElementById("registerForm_account")) humanClick(registerBtn);
const loginBtn = document.getElementById("pop2LoginBtn");
if (loginBtn && !registerBtn && !emailInput) humanClick(loginBtn);
}, 1000);
})();