MCPcopy Create free account
hub / github.com/Yantesoft/LinuxdoAssistant / createSwitchButton

Function createSwitchButton

linuxdo-helper.user.js:333–370  ·  view source on GitHub ↗

* 创建控制开关按钮 * @returns {HTMLElement} 开关按钮的 li 元素

()

Source from the content-addressed store, hash-verified

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 * 查找聊天按钮元素

Callers 1

createSwitchIconFunction · 0.85

Calls 4

getSwitchStateFunction · 0.85
createSVGIconFunction · 0.85
toggleSwitchFunction · 0.85

Tested by

no test coverage detected