binance helper

This commit is contained in:
thuanle
2025-07-31 21:29:44 +07:00
parent 73f7128683
commit 2c8299a89c

View File

@@ -56,6 +56,40 @@
delay: (ms) => new Promise(resolve => setTimeout(resolve, ms)), delay: (ms) => new Promise(resolve => setTimeout(resolve, ms)),
}; };
// ====== DOM helpers ======
TL.ui = {
isVisible: (el) => {
if (!el) return false;
const cs = getComputedStyle(el);
if (cs.display === 'none' || cs.visibility === 'hidden' || cs.opacity === '0') return false;
return (el.offsetWidth + el.offsetHeight) > 0;
},
isDisabled: (el) => {
return el?.disabled === true || el?.getAttribute('aria-disabled') === 'true';
},
isInViewport: (el) => {
if (!el) return false;
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
},
click: (el) => {
if (el && typeof el.click === 'function') el.click();
},
scrollToView: (el, behavior = 'smooth') => {
el?.scrollIntoView?.({ behavior, block: 'center' });
},
};
// ====== Network helpers (GM_xmlhttpRequest) ====== // ====== Network helpers (GM_xmlhttpRequest) ======
TL.net = { TL.net = {
gmRequest(url, init = {}) { gmRequest(url, init = {}) {
@@ -175,6 +209,35 @@
} }
// ====== BINANCE (isLoggedIn) ======
const BINANCE = {
detectLoginState: () => {
const loginBtn = document.querySelector('#toLoginPage');
const regBtn = document.querySelector('#toRegisterPage');
if (TL.dom.isVisible?.(loginBtn) || TL.dom.isVisible?.(regBtn)) return false;
if (!loginBtn && !regBtn) return true;
return null; // đang load hoặc chưa rõ
},
isLoggedIn: async (timeoutMs = 6000, pollMs = 200) => {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const state = BINANCE.detectLoginState();
if (state !== null) {
TL.log(`[BINANCE] isLoggedIn => ${state ? 'true' : 'false'}`);
return state;
}
await TL.delay(pollMs);
}
const fallback = BINANCE.detectLoginState() ?? false;
TL.log(`[BINANCE] isLoggedIn (timeout, fallback) => ${fallback ? 'true' : 'false'}`);
return fallback;
},
};
// ====== Main ====== // ====== Main ======
async function welcome_message() { async function welcome_message() {
@@ -183,7 +246,7 @@
const res = await BAF.ping(); const res = await BAF.ping();
const resStr = const resStr =
`Server: ${s.label} (${s.url})\n` + `Server: ${s.label} (${s.url})\n` +
`Status: ${res.ok ? 'Connected ✅' : 'Failed ❌'} (${res.status})`; `Status: ${res.ok ? 'Connected ✅' : 'Failed ❌'} (${res.status})`;
TL.log(resStr); TL.log(resStr);
} }