Skip to content

Commit af9ad69

Browse files
committed
feat: 為 Agent 設置指令添加複製按鈕
- 在設置指令區塊右上角添加複製按鈕 - 實現複製功能,支援現代 Clipboard API 和降級方案 - 複製成功後顯示視覺回饋(綠色勾號) - 解決使用者無法方便複製 Agent 指令的問題
1 parent a826705 commit af9ad69

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

index.html

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ <h3>🚀 快速開始</h3>
529529

530530
<details style="margin-top: 15px; background: #f0f7ff; padding: 15px; border-radius: 8px; border: 1px solid #667eea;">
531531
<summary style="cursor: pointer; font-weight: bold; color: #667eea;">🤖 Agent 快速設置指令(點擊展開)</summary>
532-
<pre style="margin-top: 10px; background: white; padding: 15px; border-radius: 5px; font-size: 0.9rem; overflow-x: auto;">請幫我設置 GitHub Copilot 教學專案環境:
532+
<div style="position: relative;">
533+
<button onclick="copyAgentPrompt()" style="position: absolute; top: 15px; right: 15px; padding: 5px 10px; background: #667eea; color: white; border: none; border-radius: 4px; font-size: 12px; cursor: pointer; z-index: 10;">
534+
複製
535+
</button>
536+
<pre id="agentPrompt" style="margin-top: 10px; background: white; padding: 15px; padding-right: 60px; border-radius: 5px; font-size: 0.9rem; overflow-x: auto;">請幫我設置 GitHub Copilot 教學專案環境:
533537

534538
1. 首先檢查目前位置並決定克隆位置:
535539
- 如果在 VS Code 中已有開啟的專案,請詢問我是否要在當前目錄的父目錄克隆
@@ -556,6 +560,7 @@ <h3>🚀 快速開始</h3>
556560
7. 檢查並設定 VS Code 的 Copilot 語言為繁體中文
557561

558562
完成後請告訴我設置狀態,並直接開啟 index.html 預覽教學內容。</pre>
563+
</div>
559564
</details>
560565

561566
<div style="text-align: center; margin-top: 20px; display: flex; gap: 15px; justify-content: center; flex-wrap: wrap;">
@@ -690,6 +695,50 @@ <h2>📚 8 個學習場景</h2>
690695
</div>
691696

692697
<script>
698+
// 複製 Agent 設置指令
699+
async function copyAgentPrompt() {
700+
const promptElement = document.getElementById('agentPrompt');
701+
const button = event.target;
702+
const originalText = button.textContent;
703+
704+
try {
705+
await navigator.clipboard.writeText(promptElement.textContent);
706+
button.textContent = '✓ 已複製';
707+
button.style.background = '#48bb78';
708+
709+
setTimeout(() => {
710+
button.textContent = originalText;
711+
button.style.background = '#667eea';
712+
}, 2000);
713+
} catch (err) {
714+
// 降級方案
715+
const textArea = document.createElement('textarea');
716+
textArea.value = promptElement.textContent;
717+
textArea.style.position = 'fixed';
718+
textArea.style.left = '-999999px';
719+
document.body.appendChild(textArea);
720+
textArea.select();
721+
722+
try {
723+
document.execCommand('copy');
724+
button.textContent = '✓ 已複製';
725+
button.style.background = '#48bb78';
726+
727+
setTimeout(() => {
728+
button.textContent = originalText;
729+
button.style.background = '#667eea';
730+
}, 2000);
731+
} catch (err) {
732+
button.textContent = '複製失敗';
733+
setTimeout(() => {
734+
button.textContent = originalText;
735+
}, 2000);
736+
}
737+
738+
document.body.removeChild(textArea);
739+
}
740+
}
741+
693742
// 儲存和取得捲動位置
694743
function saveScrollPosition(path, position) {
695744
localStorage.setItem(`scroll_${path}`, position);

0 commit comments

Comments
 (0)