-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionToolbox.html
More file actions
149 lines (136 loc) · 6.31 KB
/
Copy pathFunctionToolbox.html
File metadata and controls
149 lines (136 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script>
// --- 1. 我幫您加入的「錯誤處理」函數 ---
function showError_(error) {
alert('側邊欄後端錯誤:\n' + (error.message || error));
// 讓關鍵按鈕恢復可用,以便重試
document.querySelectorAll('button').forEach(b => b.disabled = false);
}
// --- 2. 頁籤 (Tabs) 切換功能 ---
document.querySelectorAll('.tab').forEach(t=>{
t.onclick = () => {
document.querySelectorAll('.tab').forEach(x=>x.classList.remove('active'));
document.querySelectorAll('.panel').forEach(x=>x.classList.remove('active'));
t.classList.add('active');
document.getElementById('panel-'+t.dataset.key).classList.add('active');
};
});
// --- 3.「設定」面板的函數 (補完您缺失的部分) ---
function loadConfig() {
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function(cfg){
['GEMINI_API_KEY','OPENAI_API_KEY','ROOT_FOLDER_ID','TARGET_FOLDERS_JSON',
'DRY_RUN','BATCH_LIMIT','INCLUDE_SUBFOLDERS','USE_ADVANCED_MOVE'
].forEach(k=>{
if (cfg[k] !== undefined && document.getElementById(k)) {
document.getElementById(k).value = String(cfg[k]);
}
});
document.querySelectorAll('button').forEach(b => b.disabled = false);
})
.withFailureHandler(showError_) // 呼叫錯誤處理
.getConfigForUI_();
}
function saveConfig() {
// 這是您被截斷的函數,我已補完
const payload = {
GEMINI_API_KEY: document.getElementById('GEMINI_API_KEY').value,
OPENAI_API_KEY: document.getElementById('OPENAI_API_KEY').value,
ROOT_FOLDER_ID: document.getElementById('ROOT_FOLDER_ID').value,
TARGET_FOLDERS_JSON: document.getElementById('TARGET_FOLDERS_JSON').value,
DRY_RUN: document.getElementById('DRY_RUN').value,
BATCH_LIMIT: document.getElementById('BATCH_LIMIT').value,
INCLUDE_SUBFOLDERS: document.getElementById('INCLUDE_SUBFOLDERS').value,
USE_ADVANCED_MOVE: document.getElementById('USE_ADVANCED_MOVE').value
};
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function(msg) {
alert('成功:' + msg);
document.querySelectorAll('button').forEach(b => b.disabled = false); // Re-enable
})
.withFailureHandler(showError_)
.saveConfigFromUI_(payload);
}
// --- 4.「快操作」面板的函數 (補完) ---
function approveIds() {
const raw = document.getElementById('approve_ids').value;
if (!raw) return alert('請貼上 ID');
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function(count) {
alert('操作成功:已批准 ' + count + ' 個 ID。');
document.getElementById('approve_ids').value = ''; // 清空
document.querySelectorAll('button').forEach(b => b.disabled = false);
})
.withFailureHandler(showError_)
.approveIDsFromUI_(raw);
}
function scanSuggest() {
if (!confirm('即將執行「掃描並產生 AI 建議」,是否繼續?')) return;
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function() {
alert('「掃描」已在後端觸發。請稍後查看『📓檔案索引』工作表。');
document.querySelectorAll('button').forEach(b => b.disabled = false);
})
.withFailureHandler(showError_)
.callScanAndSuggest_();
}
function execApproved() {
if (!confirm('即將執行「所有已批准(OK)」的項目,是否繼續?')) return;
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function() {
alert('「執行」已在後端觸發。請稍後查看『📓檔案索引』工作表中的狀態。');
document.querySelectorAll('button').forEach(b => b.disabled = false);
})
.withFailureHandler(showError_)
.callExecuteApproved_();
}
// --- 5.「函式工具箱」面板的函數 (補完) ---
function loadSnippet() {
const key = document.getElementById('snippet_key').value;
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function(code) {
document.getElementById('snippet_text').value = code;
document.querySelectorAll('button').forEach(b => b.disabled = false);
})
.withFailureHandler(showError_)
.getFunctionSnippet_(key);
}
function copySnippet() {
const text = document.getElementById('snippet_text').value;
if (!text) return alert('請先載入原始碼');
navigator.clipboard.writeText(text).then(function() {
alert('已複製到剪貼簿!');
}, function(err) {
alert('複製失敗: ' + err);
});
}
function copyBundle() {
document.querySelectorAll('button').forEach(b => b.disabled = true);
google.script.run
.withSuccessHandler(function(code) {
document.getElementById('snippet_text').value = code;
navigator.clipboard.writeText(code).then(function() {
alert('『依賴+執行器』整包已複製到剪貼簿!');
document.querySelectorAll('button').forEach(b => b.disabled = false);
}, function(err) {
alert('複製失敗: ' + err);
document.querySelectorAll('button').forEach(b => b.disabled = false);
});
})
.withFailureHandler(showError_)
.getFunctionBundle_();
}
// --- 6. (最關鍵) 應用程式初始化 ---
// (這會自動執行、載入設定,並在成功後「啟用」所有按鈕)
function initApp_() {
document.querySelectorAll('button').forEach(b => b.disabled = true);
loadConfig(); // 載入設定,loadConfig 內部會在成功後啟用按鈕
}
// 立即執行初始化
initApp_();
</script>