Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/binance-orderbook-trade.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions src/binance-orderbook-trade/dom/chart-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/binance-orderbook-trade/index.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
21 changes: 18 additions & 3 deletions test/dom/binance-orderbook-trade/chart-orders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ function createChartMarkup({
mode = 'tradingview',
popoverId = 'chart-orders-menu',
latestPriceLabel = '最新价格',
wrapLatestPrice = false,
} = {}) {
const chartBody = mode === 'tradingview'
? '<div id="chart_futures-tradingview"><iframe id="tradingview_fixture"></iframe></div>'
: '<div data-testid="basic-chart"><iframe id="basic_fixture"></iframe></div>';
const latestPriceControl = `
<span class="bn-tooltips-wrap bn-tooltips-web w-full cursor-pointer" data-testid="latest-price">
${latestPriceLabel}
</span>
`;
const latestPriceSlot = wrapLatestPrice
? `<span class="contents">${latestPriceControl}</span>`
: latestPriceControl;
return `
<div class="chart-widget-root">
<div class="flex items-center gap-[--space-m]" data-testid="chart-toolbar">
Expand All @@ -25,9 +34,7 @@ function createChartMarkup({
<span class="bn-tooltips-wrap bn-tooltips-web" data-testid="orders-trigger">
<span class="bn-tooltips-ele" aria-describedby="${popoverId}">orders</span>
</span>
<span class="bn-tooltips-wrap bn-tooltips-web w-full cursor-pointer" data-testid="latest-price">
${latestPriceLabel}
</span>
${latestPriceSlot}
</div>
${chartBody}
</div>
Expand Down Expand Up @@ -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('<div></div>');
assert.equal(findBinanceChartOrdersTarget(missingDom.window.document), null);
Expand Down
Loading