* 创建控制开关按钮 * @returns {HTMLElement} 开关按钮的 li 元素
()
| 331 | * @returns {HTMLElement} 开关按钮的 li 元素 |
| 332 | */ |
| 333 | function createSwitchButton() { |
| 334 | const iconLi = document.createElement('li'); |
| 335 | iconLi.className = 'header-dropdown-toggle'; |
| 336 | |
| 337 | const iconLink = document.createElement('a'); |
| 338 | iconLink.href = '#'; |
| 339 | iconLink.className = 'btn no-text icon btn-flat'; |
| 340 | iconLink.tabIndex = 0; |
| 341 | |
| 342 | const isEnabled = getSwitchState(); |
| 343 | iconLink.title = isEnabled ? '停止Linuxdo助手' : '启动Linuxdo助手'; |
| 344 | |
| 345 | const svg = createSVGIcon(isEnabled ? '#pause' : '#play'); |
| 346 | |
| 347 | iconLink.appendChild(svg); |
| 348 | iconLi.appendChild(iconLink); |
| 349 | |
| 350 | iconLink.addEventListener('click', (e) => { |
| 351 | e.preventDefault(); |
| 352 | e.stopPropagation(); |
| 353 | |
| 354 | toggleSwitch(); |
| 355 | |
| 356 | const newState = getSwitchState(); |
| 357 | const use = svg.querySelector('use'); |
| 358 | |
| 359 | if (use) { |
| 360 | use.setAttribute('href', newState ? '#pause' : '#play'); |
| 361 | } |
| 362 | |
| 363 | iconLink.title = newState ? '停止Linuxdo助手' : '启动Linuxdo助手'; |
| 364 | iconLink.classList.toggle('active', newState); |
| 365 | |
| 366 | updateFloatingSliderVisibility(); |
| 367 | }); |
| 368 | |
| 369 | return iconLi; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * 查找聊天按钮元素 |
no test coverage detected