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

Function insertSwitchButton

linuxdo-helper.user.js:416–450  ·  view source on GitHub ↗

* 将开关按钮插入到页面中 * @param {HTMLElement} buttonElement - 开关按钮元素

(buttonElement)

Source from the content-addressed store, hash-verified

414 * @param {HTMLElement} buttonElement - 开关按钮元素
415 */
416 function insertSwitchButton(buttonElement) {
417 if (document.getElementById('linuxdo-helper-switch')) {
418 return;
419 }
420
421 buttonElement.id = 'linuxdo-helper-switch';
422
423 const chatButton = document.querySelector(SELECTORS.chatButton);
424
425 if (chatButton?.parentNode) {
426 chatButton.parentNode.insertBefore(buttonElement, chatButton.nextSibling);
427 return;
428 }
429
430 const fallbackPosition = findFallbackInsertPosition();
431
432 if (fallbackPosition?.parentNode) {
433 fallbackPosition.parentNode.insertBefore(buttonElement, fallbackPosition.nextSibling);
434 return;
435 }
436
437 const header = document.querySelector(SELECTORS.header) || document.querySelector('header');
438
439 if (header) {
440 const headerList = header.querySelector('ul') || header.querySelector('nav');
441
442 if (headerList) {
443 headerList.appendChild(buttonElement);
444 } else {
445 header.insertBefore(buttonElement, header.firstChild);
446 }
447 } else {
448 console.log('【错误】未找到按钮插入位置!');
449 }
450 }
451
452 /**
453 * 创建并插入开关图标到页面

Callers 1

createSwitchIconFunction · 0.85

Calls 1

Tested by

no test coverage detected