|
1 | 1 | <div class="parent"> |
| 2 | + <div class="search-popup"></div> |
2 | 3 | <div class="timer-container"> |
3 | 4 | <div id="timer-line"></div> |
4 | 5 | </div> |
5 | 6 | <div class="otps"></div> |
6 | 7 | </div> |
7 | 8 | <style> |
| 9 | +
|
| 10 | + .search-popup { |
| 11 | + position: fixed; |
| 12 | + top: 10px; |
| 13 | + left: 10px; |
| 14 | + background-color: #2e2e2e; |
| 15 | + border-bottom: 1px solid #d6d6d6; |
| 16 | + padding: 5px 10px; |
| 17 | + z-index: 1000; |
| 18 | + font-size: 18px; |
| 19 | + max-width: 90vw; |
| 20 | + white-space: nowrap; |
| 21 | + overflow: hidden; |
| 22 | + text-overflow: ellipsis; |
| 23 | + } |
| 24 | +
|
8 | 25 | .otp, .otps, .parent { |
9 | 26 | display: flex |
10 | 27 | } |
|
60 | 77 |
|
61 | 78 | <script> |
62 | 79 |
|
63 | | - function spaceOutCode(code) { |
| 80 | + let searchQuery = ''; |
| 81 | +
|
| 82 | + const showSearchPopup = () => { |
| 83 | + let popup = document.querySelector('.search-popup'); |
| 84 | + if (searchQuery === '') { |
| 85 | + popup.style.display = 'none' |
| 86 | + } else { |
| 87 | + popup.style.display = '' |
| 88 | + } |
| 89 | + popup.textContent = searchQuery; |
| 90 | + }; |
| 91 | +
|
| 92 | + const filterOtps = () => { |
| 93 | + const allOtps = document.querySelectorAll('.otp'); |
| 94 | + const query = searchQuery.toLowerCase(); |
| 95 | +
|
| 96 | + allOtps.forEach(otp => { |
| 97 | + const name = otp.querySelector('.otp_name').textContent.toLowerCase(); |
| 98 | + otp.style.display = name.includes(query) ? '' : 'none'; |
| 99 | + }); |
| 100 | + }; |
| 101 | +
|
| 102 | + document.addEventListener('keydown', (e) => { |
| 103 | + if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) { |
| 104 | + searchQuery += e.key; |
| 105 | + showSearchPopup(); |
| 106 | + filterOtps(); |
| 107 | + } else if (e.key === 'Backspace') { |
| 108 | + searchQuery = searchQuery.slice(0, -1); |
| 109 | + showSearchPopup(); |
| 110 | + filterOtps(); |
| 111 | + } else if (e.key === 'Escape') { |
| 112 | + searchQuery = ''; |
| 113 | + showSearchPopup(); |
| 114 | + filterOtps(); |
| 115 | + } |
| 116 | + }); |
| 117 | +
|
| 118 | + const spaceOutCode = code => { |
64 | 119 | const len = code.length; |
65 | 120 |
|
66 | 121 | if (len % 2 === 0) { |
|
70 | 125 | const middle = Math.floor(len / 2); |
71 | 126 | return code.slice(0, middle) + ' ' + code[middle] + ' ' + code.slice(middle + 1); |
72 | 127 | } |
73 | | - } |
| 128 | + }; |
| 129 | +
|
| 130 | + const updateTimer = () => { |
| 131 | + const progress = (30 - (Date.now() / 1000) % 30) / 30 * 100; |
| 132 | + document.getElementById('timer-line').style.width = progress + '%'; |
| 133 | + }; |
74 | 134 |
|
75 | 135 | const url_prefix = "{{ url_prefix }}" |
76 | | - const token = "{{ token }}"; |
77 | | - const proto = location.protocol === 'https:' ? 'wss' : 'ws'; |
78 | | - const socket = new WebSocket(`${proto}://${location.host}${url_prefix}ws?token=${encodeURIComponent(token)}`); |
| 136 | + const socket = new WebSocket(`${(location.protocol === 'https:' ? 'wss' : 'ws')}://${location.host}${url_prefix}ws?token=${encodeURIComponent("{{ token }}")}`); |
79 | 137 | const otpContainer = document.querySelector('.otps'); |
80 | 138 |
|
81 | 139 | socket.onmessage = (event) => { |
|
100 | 158 | }); |
101 | 159 | }; |
102 | 160 | }); |
| 161 | + filterOtps() |
103 | 162 | }; |
104 | 163 |
|
105 | 164 | socket.onclose = () => { |
106 | 165 | window.location.href = url_prefix; |
107 | 166 | }; |
108 | 167 |
|
109 | | - function updateTimer() { |
110 | | - const progress = (30 - (Date.now() / 1000) % 30) / 30 * 100; |
111 | | - document.getElementById('timer-line').style.width = progress + '%'; |
112 | | - } |
113 | | -
|
114 | 168 | setInterval(updateTimer, 10); |
115 | 169 | updateTimer(); |
| 170 | + showSearchPopup(); |
116 | 171 |
|
117 | 172 | </script> |
118 | 173 |
|
0 commit comments