From 76093dc6eb643948416cc0a676cb02c786820023 Mon Sep 17 00:00:00 2001 From: thuanle Date: Wed, 30 Jul 2025 18:28:06 +0700 Subject: [PATCH] Add Binance Alpha Farm Agent UserScript This commit introduces a new UserScript for Binance Alpha Farm, designed to enhance user experience by providing a welcome popup and utility functions for managing input fields. The script includes features for creating and updating popups, as well as handling user interactions effectively. --- agent.user.js | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 agent.user.js diff --git a/agent.user.js b/agent.user.js new file mode 100644 index 0000000..58dd7fe --- /dev/null +++ b/agent.user.js @@ -0,0 +1,151 @@ +// ==UserScript== +// @name Binance Alpha Farm Agent +// @namespace http://baf.thuanle.me +// @version 2025.07.30 +// @author TL +// @match https://www.binance.com/en/alpha/bsc/* +// @run-at document-idle +// @grant GM_setValue +// @grant GM_getValue +// ==/UserScript== + +(async () => { + 'use strict'; + + // Utility functions + const TL = { + log: (msg, ...args) => console.log(`[TL] ${msg}`, ...args), + delay: ms => new Promise(resolve => setTimeout(resolve, ms)), + getEl: sel => document.querySelector(sel), + waitForEl: async (sel, timeout = 10000) => { + const start = Date.now(); + while (Date.now() - start < timeout) { + const el = document.querySelector(sel); + if (el) return el; + await TL.delay(100); + } + throw new Error(`waitForEl: Timeout waiting for ${sel}`); + }, + + eventFillFloatInputById(id, value) { + const input = document.getElementById(id); + if (!input) return; + const current = parseFloat(input.value); + const target = parseFloat(value); + if (Math.abs(current - target) < 1e-8) return; + + const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set; + setter.call(input, value); + input.dispatchEvent(new Event('input', { bubbles: true })); + } + }; + + // POP UP HELPER + const PopupHelper = { + defaultStyle: ` + position: fixed; + bottom: 20px; + background: white; + color: #000; + border: 1px solid #ccc; + padding: 12px 16px; + border-radius: 6px; + box-shadow: 0 4px 12px rgba(0,0,0,0.2); + z-index: 999999; + font-family: sans-serif; + font-size: 12px; + display: block !important; + visibility: visible !important; + opacity: 1 !important; + `, + + createOrUpdatePopup(id, options = {}) { + try { + const { + html = '', + position = 'bottom-right', + customStyle = '', + onClick = null + } = options; + + TL.log(`🔍 Creating/updating popup with ID: ${id}`); + + let popup = document.getElementById(id); + if (!popup) { + popup = document.createElement('div'); + popup.id = id; + document.body.appendChild(popup); + TL.log(`🔍 Created new popup element with ID: ${id}`); + } else { + TL.log(`🔍 Found existing popup with ID: ${id}`); + } + + // Set position based on position parameter + let positionStyle = ''; + switch (position) { + case 'bottom-right': + positionStyle = 'right: 20px;'; + break; + case 'bottom-left': + positionStyle = 'left: 20px;'; + break; + case 'top-right': + positionStyle = 'top: 20px; right: 20px;'; + break; + case 'top-left': + positionStyle = 'top: 20px; left: 20px;'; + break; + case 'center': + positionStyle = 'top: 50%; left: 50%; transform: translate(-50%, -50%);'; + break; + default: + positionStyle = 'right: 20px;'; + } + + // Apply styles + const finalStyle = this.defaultStyle + positionStyle + customStyle; + popup.style.cssText = finalStyle; + TL.log(`🔍 Applied styles to popup: ${finalStyle.substring(0, 100)}...`); + + // Set content + popup.innerHTML = html; + TL.log(`🔍 Set HTML content to popup (length: ${html.length})`); + + // Add click handler if provided + if (onClick && typeof onClick === 'function') { + popup.onclick = onClick; + } + + TL.log(`✅ Popup ${id} created/updated successfully`); + return popup; + } catch (error) { + TL.log(`❌ Error in createOrUpdatePopup: ${error.message}`); + return null; + } + }, + + removePopup(id) { + const popup = document.getElementById(id); + if (popup) { + popup.remove(); + } + }, + + + }; + + // Main script logic + // show welcome popup + PopupHelper.createOrUpdatePopup('welcome-popup', { + html: ` +
+

Welcome to Binance Alpha Farm Agent

+

This script will help you manage your Binance Alpha Farm tasks more efficiently.

+

Click here to learn more.

+ +
+ `, onClick: () => { + PopupHelper.removePopup('welcome-popup'); + } + }); +})(); \ No newline at end of file