File size: 3,934 Bytes
5f20dc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* help.js — contextual "?" tooltips.
   Usage: add data-help="key" to any element.
   Hover on desktop, tap on mobile. */
(function () {
  'use strict';

  var HELP = {
    zscore: "How far the current price is from its 20-day average. Negative = below average.",
    rsi: "0–100 momentum gauge. Under 30 = oversold, over 70 = overbought.",
    atr: "How far TP/SL are placed from price. 2× = moderate, 3× = wider targets.",
    basis: "Difference between futures and spot price. Positive = contango, negative = backwardation.",
    signal: "Buy signal fires when Z-Score, momentum, volatility, and RSI all pass criteria.",
    tp: "Take Profit. Price target for automatic sell at a gain.",
    sl: "Stop Loss. Price at which the position closes to limit losses.",
    momentum: "7-day price change as a percentage.",
    volatility: "Standard deviation of daily returns over 20 days. Lower = calmer.",
    score: "Composite score combining Z-Score, momentum, volatility, and RSI.",
    invest: "Total USDT to spread across your selected coins.",
    contango: "Futures trade above spot. Market expects higher prices; longs pay shorts.",
    backwardation: "Futures trade below spot. Signals tight supply or bearish sentiment.",
    conservative: "Scans top 20 by market cap with tight stops.",
    risk: "Includes lower-liquidity, high-volatility coins with wider stops."
  };

  var activeTip = null;

  function buildIcon(key) {
    var span = document.createElement('span');
    span.className = 'help-icon';
    span.setAttribute('data-help-key', key);
    span.textContent = '?';
    return span;
  }

  function showTip(target, key) {
    hideTip();
    var text = HELP[key] || 'Info';
    var tip = document.createElement('div');
    tip.className = 'help-tip';
    tip.textContent = text;
    document.body.appendChild(tip);

    var rect = target.getBoundingClientRect();
    var tipRect = tip.getBoundingClientRect();
    var scrollY = window.scrollY || window.pageYOffset;
    var scrollX = window.scrollX || window.pageXOffset;

    // Position: prefer below, flip above if no room
    var top, left;
    left = rect.left + scrollX + (rect.width / 2) - (tipRect.width / 2);
    // Clamp to viewport
    if (left < 8) left = 8;
    if (left + tipRect.width > window.innerWidth - 8) {
      left = window.innerWidth - tipRect.width - 8;
    }

    var spaceBelow = window.innerHeight - rect.bottom;
    if (spaceBelow < tipRect.height + 12) {
      top = rect.top + scrollY - tipRect.height - 8;
    } else {
      top = rect.bottom + scrollY + 8;
    }

    tip.style.top = top + 'px';
    tip.style.left = left + 'px';
    tip.style.opacity = '1';
    activeTip = tip;
  }

  function hideTip() {
    if (activeTip) {
      activeTip.remove();
      activeTip = null;
    }
  }

  function attach() {
    var nodes = document.querySelectorAll('[data-help]');
    nodes.forEach(function (el) {
      if (el.querySelector(':scope > .help-icon')) return;
      var key = el.getAttribute('data-help');
      var icon = buildIcon(key);
      el.appendChild(icon);

      icon.addEventListener('mouseenter', function () { showTip(icon, key); });
      icon.addEventListener('mouseleave', function () { hideTip(); });
      icon.addEventListener('click', function (e) {
        e.stopPropagation();
        e.preventDefault();
        if (activeTip && activeTip.getAttribute('data-tip-key') === key) {
          hideTip();
        } else {
          showTip(icon, key);
          if (activeTip) activeTip.setAttribute('data-tip-key', key);
        }
      });
    });
  }

  document.addEventListener('click', function (e) {
    if (!e.target.classList || !e.target.classList.contains('help-icon')) {
      hideTip();
    }
  });

  window.HelpTips = { attach: attach, HELP: HELP };

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', attach);
  } else {
    attach();
  }
})();