copyToClipboard: function (text) {
return new Promise(function (resolve) {
var value = String(text == null ? '' : text);
var clipboard = null;
try {
clipboard = (typeof navigator !== 'undefined' && navigator && navigator.clipboard) ? navigator.clipboard : null;
} catch (e) {
clipboard = null;
}
if (clipboard && typeof clipboard.writeText === 'function') {
clipboard.writeText(value).then(function () {
resolve(true);
}).catch(function () {
resolve(fallbackCopy(value));
});
return;
}
resolve(fallbackCopy(value));
function fallbackCopy(v) {
try {
var textarea = document.createElement('textarea');
textarea.value = v;
textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed';
textarea.style.top = '-9999px';
textarea.style.left = '0';
textarea.style.width = '1px';
textarea.style.height = '1px';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try { textarea.setSelectionRange(0, textarea.value.length); } catch (e) {}
var ok = false;
try {
ok = document.execCommand('copy');
} catch (e) {
ok = false;
}
document.body.removeChild(textarea);
return ok;
} catch (e) {
return false;
}
}
});
},
function showToast(message, duration) {
duration = typeof duration === 'number' ? duration : 2000;
var toast = document.createElement('div');
toast.textContent = message;
toast.style.position = 'fixed';
toast.style.left = '50%';
toast.style.bottom = '12%';
toast.style.transform = 'translateX(-50%)';
toast.style.maxWidth = '80%';
toast.style.padding = '10px 14px';
toast.style.background = 'rgba(0,0,0,0.75)';
toast.style.color = '#fff';
toast.style.fontSize = '14px';
toast.style.lineHeight = '1.4';
toast.style.borderRadius = '6px';
toast.style.zIndex = '2147483647';
toast.style.pointerEvents = 'none';
toast.style.opacity = '0';
toast.style.transition = 'opacity 200ms ease';
document.body.appendChild(toast);
requestAnimationFrame(function () {
toast.style.opacity = '1';
});
setTimeout(function () {
toast.style.opacity = '0';
toast.addEventListener('transitionend', function () {
if (toast && toast.parentNode) {
toast.parentNode.removeChild(toast);
}
}, { once: true });
}, duration);
}