MCPcopy
hub / github.com/Bistutu/FluentRead / createTranslationTooltip

Function createTranslationTooltip

entrypoints/content.ts:832–866  ·  view source on GitHub ↗

* 创建并显示翻译提示弹窗

(element: HTMLElement, message: string, type: 'translating' | 'success' | 'error')

Source from the content-addressed store, hash-verified

830 * 创建并显示翻译提示弹窗
831 */
832function createTranslationTooltip(element: HTMLElement, message: string, type: 'translating' | 'success' | 'error'): HTMLElement {
833 // 移除已存在的提示
834 removeExistingTooltip();
835
836 const tooltip = document.createElement('div');
837 tooltip.className = `fluent-input-tooltip ${type}`;
838 tooltip.id = 'fluent-input-translation-tooltip';
839
840 // 添加图标和文字
841 const icon = getTooltipIcon(type);
842 tooltip.innerHTML = `${icon} ${message}`;
843
844 // 计算位置
845 const rect = element.getBoundingClientRect();
846 const tooltipTop = rect.bottom + window.scrollY + 12;
847 const tooltipLeft = rect.left + window.scrollX + (rect.width / 2);
848
849 tooltip.style.top = `${tooltipTop}px`;
850 tooltip.style.left = `${tooltipLeft}px`;
851 tooltip.style.transform = 'translateX(-50%)';
852
853 // 如果禁用动画,直接显示,否则使用淡入效果
854 if (!config.animations) {
855 tooltip.style.opacity = '1';
856 tooltip.style.transform = 'translateX(-50%) translateY(0)';
857 } else {
858 tooltip.style.opacity = '0';
859 setTimeout(() => {
860 tooltip.classList.add('show');
861 }, 10);
862 }
863
864 document.body.appendChild(tooltip);
865 return tooltip;
866}
867
868/**
869 * 获取提示图标

Callers 1

Calls 2

removeExistingTooltipFunction · 0.85
getTooltipIconFunction · 0.85

Tested by

no test coverage detected