From 9aa79dacbb44d888fee89c82d5c8ed49624f058a Mon Sep 17 00:00:00 2001 From: Bro Date: Fri, 24 Jul 2026 19:53:41 +0700 Subject: [PATCH] fix: copy token pake execCommand() biar jalan di HTTP --- resources/views/settings/sync.blade.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/resources/views/settings/sync.blade.php b/resources/views/settings/sync.blade.php index 93f59da..2125de8 100644 --- a/resources/views/settings/sync.blade.php +++ b/resources/views/settings/sync.blade.php @@ -174,17 +174,24 @@ const el = document.getElementById('ejurnalTokenDisplay'); const btn = document.getElementById('copyTokenBtn'); if (!el || !btn) return; - navigator.clipboard.writeText(el.textContent.trim()).then(() => { + + // Select the text + const range = document.createRange(); + range.selectNodeContents(el); + const sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + + // Copy using execCommand (works on HTTP too) + try { + document.execCommand('copy'); + sel.removeAllRanges(); btn.innerHTML = ' Tersalin'; setTimeout(() => { btn.innerHTML = ' Salin'; }, 2000); - }).catch(() => { - // Fallback: select text manually - const range = document.createRange(); - range.selectNodeContents(el); - const sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - }); + } catch (err) { + // Fallback: show manual instruction + alert('Tekan Ctrl+C (Cmd+C di Mac) untuk menyalin token.'); + } } function copyKesiswaanToken() {