-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinks-config.js
More file actions
85 lines (79 loc) · 2.61 KB
/
links-config.js
File metadata and controls
85 lines (79 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Element Links Configuration and Utilities
// Shared configuration for element linking feature
//
// Format: 'hostname': { 'label': { selector: 'css-selector', description: 'human-readable description' } }
// Supports:
// - Element IDs: '#tv_chart_container'
// - Content-based: 'div:contains("Open Interest")'
// - Complex selectors: 'div:has(div:contains("Orderbook"))'
const ELEMENT_LINK_CONFIG = {
// Hyperliquid trading interface
'app.hyperliquid.xyz': {
'chart': {
selector: '#tv_chart_container',
description: 'Trading Chart'
},
'info': {
selector: '#coinInfo',
description: 'Coin Information Panel'
},
'orderbook': {
selector: "div:has(div:contains('Orderbook'))",
description: 'Order Book'
},
'trades': {
selector: "div:has(div:contains('Recent Trades'))",
description: 'Recent Trades'
},
'positions': {
selector: "div:has(div:contains('Positions'))",
description: 'Positions Panel'
},
'orders': {
selector: "div:has(div:contains('Orders'))",
description: 'Orders Panel'
},
'openinterest': {
selector: "div:contains('Open Interest')",
description: 'Open Interest'
},
'funding': {
selector: "div:contains('Funding Rate')",
description: 'Funding Rate'
},
'volume': {
selector: "div:contains('24h Volume')",
description: '24h Volume'
}
}
// Future sites can be added here
// 'some.other.site': {
// 'label': { selector: 'css-selector', description: 'description' }
// }
};
// Element link processing function
function processElementLinks(content, config) {
if (!config) {
return content;
}
// Regex to find #word patterns. The # character is not escaped by HTML escaping.
const tagRegex = /#(\w+)/g;
return content.replace(tagRegex, (match, tagLabel) => {
try {
const elementConfig = config[tagLabel.toLowerCase()];
if (elementConfig && elementConfig.selector) {
return `<a href="#" class="hl-element-link" data-element-selector="${elementConfig.selector}" title="Scroll to ${elementConfig.description}">#${tagLabel}</a>`;
}
} catch (error) {
console.warn('[ElementLinks] Failed to process tag:', tagLabel, error);
}
// If the tag is not in our config or processing failed, return it as plain text.
return match;
});
}
// Export for ES6 modules (sidepanel only)
export { ELEMENT_LINK_CONFIG, processElementLinks };
// Export for CommonJS (for potential Node.js usage)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { ELEMENT_LINK_CONFIG, processElementLinks };
}