Fix Google Form Grid parser, survey display, and instant copy link button

This commit is contained in:
pongpon pitisuk
2026-09-12 15:08:23 +07:00
parent e01d01464a
commit 0e09259c9d
5 changed files with 188 additions and 65 deletions
+57
View File
@@ -43,6 +43,63 @@ const API = {
}
};
// ============================================================
// Universal Clipboard Helper (HTTP & HTTPS compatible)
// ============================================================
function copyTextToClipboard(text, btnElement) {
if (!text) return;
const showSuccess = () => {
if (typeof Toast !== 'undefined') Toast.success('คัดลอกลิงก์สำเร็จแล้ว!');
if (btnElement) {
const origHtml = btnElement.innerHTML;
btnElement.innerHTML = '✅ คัดลอกแล้ว!';
btnElement.style.backgroundColor = '#16a34a';
btnElement.style.color = '#ffffff';
setTimeout(() => {
btnElement.innerHTML = origHtml;
btnElement.style.backgroundColor = '';
btnElement.style.color = '';
}, 2000);
}
};
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(showSuccess).catch(() => fallbackCopy(text, showSuccess));
} else {
fallbackCopy(text, showSuccess);
}
}
function fallbackCopy(text, callback) {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed';
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = '0';
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand('copy');
if (successful && callback) {
callback();
} else if (!successful && typeof Toast !== 'undefined') {
Toast.error('กรุณากดคัดลอกด้วยตนเอง');
}
} catch (err) {
if (typeof Toast !== 'undefined') Toast.error('ไม่สามารถคัดลอกได้');
}
document.body.removeChild(textArea);
}
// ============================================================
// Auth State
// ============================================================