MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / copyTextFromCode

Function copyTextFromCode

src/giffgaff/js/modules/utils.js:229–255  ·  view source on GitHub ↗
(codeElementId, btnEl)

Source from the content-addressed store, hash-verified

227 * 从code元素复制文本
228 */
229export function copyTextFromCode(codeElementId, btnEl) {
230 const el = document.getElementById(codeElementId);
231 if (!el) return;
232
233 const text = (el.textContent || '').trim();
234 if (!text) return;
235
236 copyToClipboard(text).then(() => {
237 if (btnEl) {
238 // 按钮视觉反馈保留,增强用户体验
239 const old = btnEl.innerHTML;
240 btnEl.innerHTML = `<i class="fas fa-check"></i> ${tl('已复制')}`;
241 btnEl.classList.add('btn-success');
242 btnEl.classList.remove('btn-outline-primary');
243 setTimeout(() => {
244 btnEl.innerHTML = old;
245 btnEl.classList.remove('btn-success');
246 btnEl.classList.add('btn-outline-primary');
247 }, 1500);
248 }
249 // 统一使用通知系统
250 NotificationManager.success(tl('复制成功'));
251 }).catch((e) => {
252 console.error(tl('复制失败:'), e);
253 NotificationManager.error(tl('复制失败,请手动选择文本复制'));
254 });
255}
256
257/**
258 * 获取当前语言对应的教程链接

Callers

nothing calls this directly

Calls 4

tlFunction · 0.90
copyToClipboardFunction · 0.70
successMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected