diff --git a/scripts/binance-orderbook-trade.user.js b/scripts/binance-orderbook-trade.user.js index b220054..55ded5b 100644 --- a/scripts/binance-orderbook-trade.user.js +++ b/scripts/binance-orderbook-trade.user.js @@ -3,7 +3,7 @@ // @namespace binance.orderbook.trade // @icon data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E // @icon64 data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E -// @version 2.7.145 +// @version 2.7.146 // @author jackhai9 // @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板 // @match https://www.binance.com/*/futures/* @@ -2204,6 +2204,7 @@ // src/binance-orderbook-trade/dom/chart-orders.js var ACTIVE_POPOVER_SELECTOR = ".bn-bubble.active"; var OPEN_ORDERS_LABEL_PATTERN = /^(?:当前委托|Open Orders)$/i; + var LATEST_PRICE_CONTROL_SELECTOR = ".bn-tooltips-wrap.bn-tooltips-web.w-full.cursor-pointer"; function normalizeLabel(value) { return String(value || "").replace(/\s+/g, " ").trim(); } @@ -2220,9 +2221,8 @@ if (toolbar2.children.length < 2) return false; const trigger2 = toolbar2.children[toolbar2.children.length - 2]; const latestPriceSlot = toolbar2.children[toolbar2.children.length - 1]; - return hasVisibleBox2(toolbar2) && hasVisibleBox2(trigger2) && trigger2.matches(".bn-tooltips-wrap.bn-tooltips-web") && hasVisibleBox2(latestPriceSlot) && latestPriceSlot.matches( - ".bn-tooltips-wrap.bn-tooltips-web.w-full.cursor-pointer" - ); + const latestPriceControl = latestPriceSlot.matches(LATEST_PRICE_CONTROL_SELECTOR) ? latestPriceSlot : Array.from(latestPriceSlot.children).find((child) => child.matches(LATEST_PRICE_CONTROL_SELECTOR)); + return hasVisibleBox2(toolbar2) && hasVisibleBox2(trigger2) && trigger2.matches(".bn-tooltips-wrap.bn-tooltips-web") && hasVisibleBox2(latestPriceControl); }); if (!toolbars.length) return null; if (toolbars.length > 1) { diff --git a/src/binance-orderbook-trade/dom/chart-orders.js b/src/binance-orderbook-trade/dom/chart-orders.js index fcc4ac9..4c6c2ec 100644 --- a/src/binance-orderbook-trade/dom/chart-orders.js +++ b/src/binance-orderbook-trade/dom/chart-orders.js @@ -2,6 +2,8 @@ import { findBinanceTradingViewTarget } from './tradingview-target.js'; const ACTIVE_POPOVER_SELECTOR = '.bn-bubble.active'; const OPEN_ORDERS_LABEL_PATTERN = /^(?:当前委托|Open Orders)$/i; +const LATEST_PRICE_CONTROL_SELECTOR = + '.bn-tooltips-wrap.bn-tooltips-web.w-full.cursor-pointer'; function normalizeLabel(value) { return String(value || '').replace(/\s+/g, ' ').trim(); @@ -23,13 +25,14 @@ export function findBinanceChartOrdersTarget(document) { if (toolbar.children.length < 2) return false; const trigger = toolbar.children[toolbar.children.length - 2]; const latestPriceSlot = toolbar.children[toolbar.children.length - 1]; + const latestPriceControl = latestPriceSlot.matches(LATEST_PRICE_CONTROL_SELECTOR) + ? latestPriceSlot + : Array.from(latestPriceSlot.children) + .find((child) => child.matches(LATEST_PRICE_CONTROL_SELECTOR)); return hasVisibleBox(toolbar) && hasVisibleBox(trigger) && trigger.matches('.bn-tooltips-wrap.bn-tooltips-web') - && hasVisibleBox(latestPriceSlot) - && latestPriceSlot.matches( - '.bn-tooltips-wrap.bn-tooltips-web.w-full.cursor-pointer', - ); + && hasVisibleBox(latestPriceControl); }); if (!toolbars.length) return null; if (toolbars.length > 1) { diff --git a/src/binance-orderbook-trade/index.user.js b/src/binance-orderbook-trade/index.user.js index f418b9d..c1a50e8 100644 --- a/src/binance-orderbook-trade/index.user.js +++ b/src/binance-orderbook-trade/index.user.js @@ -3,7 +3,7 @@ // @namespace binance.orderbook.trade // @icon data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E // @icon64 data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E -// @version 2.7.145 +// @version 2.7.146 // @author jackhai9 // @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板 // @match https://www.binance.com/*/futures/* diff --git a/test/dom/binance-orderbook-trade/chart-orders.test.js b/test/dom/binance-orderbook-trade/chart-orders.test.js index a068d1d..2c355b9 100644 --- a/test/dom/binance-orderbook-trade/chart-orders.test.js +++ b/test/dom/binance-orderbook-trade/chart-orders.test.js @@ -13,10 +13,19 @@ function createChartMarkup({ mode = 'tradingview', popoverId = 'chart-orders-menu', latestPriceLabel = '最新价格', + wrapLatestPrice = false, } = {}) { const chartBody = mode === 'tradingview' ? '
' : ''; + const latestPriceControl = ` + + ${latestPriceLabel} + + `; + const latestPriceSlot = wrapLatestPrice + ? `${latestPriceControl}` + : latestPriceControl; return ` @@ -76,6 +83,14 @@ test('supports the English current-price label without broad text scanning', () ); }); +test('supports Binance wrapping the current-price control in a contents slot', () => { + const { dom } = loadChartTarget({ wrapLatestPrice: true }); + assert.equal( + getBinanceChartOrdersTarget(dom.window.document).trigger.getAttribute('data-testid'), + 'orders-trigger', + ); +}); + test('find waits for a visible complete and unambiguous chart contract', () => { const missingDom = loadFixtureDom(''); assert.equal(findBinanceChartOrdersTarget(missingDom.window.document), null);