-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.html
More file actions
105 lines (88 loc) · 3.9 KB
/
Sidebar.html
File metadata and controls
105 lines (88 loc) · 3.9 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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('Stylesheet'); ?>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<header>
<div class="logo-icon">A</div>
<h1>AutoScript AI</h1>
<div class="credit-badge" onclick="openPayment()">📦 <span id="credit-count">?</span> credits</div>
</header>
<div class="chat-area" id="chat-history">
<div class="message ai">
Hello! I am your Apps Script assistant. What would you like to automate today?
</div>
</div>
<div id="error-container" class="error-msg" style="display:none;"></div>
<div class="input-container">
<textarea id="user-prompt" placeholder="Ex: Email me if cell C2 exceeds 100..."
rows="3"></textarea>
<button id="generate-btn" onclick="generateCode()">Generate & Install</button>
<button id="buy-btn" class="buy-credits-btn" style="display:none;" onclick="openPayment()">Buy Credits</button>
</div>
</div>
<script>
function generateCode() {
const prompt = document.getElementById('user-prompt').value;
const errorContainer = document.getElementById('error-container');
const buyBtn = document.getElementById('buy-btn');
if (!prompt) return;
errorContainer.style.display = 'none';
buyBtn.style.display = 'none';
addMessage(prompt, 'user');
document.getElementById('user-prompt').value = '';
// Loading simulation
const loadingMsg = addMessage("Analyzing and generating script...", "ai");
google.script.run
.withSuccessHandler((response) => {
if (response.status === 'success') {
loadingMsg.innerHTML = response.message;
updateCredits(response.credits);
// AUTOMATIC EXECUTION
const execMsg = addMessage("⚡ Applying changes...", "ai");
google.script.run
.withSuccessHandler((res) => {
execMsg.innerHTML = res.message;
})
.runGeneratedCode(response.code);
} else {
loadingMsg.innerHTML = response.message;
if (response.message.includes('exhausted')) {
buyBtn.style.display = 'block';
}
}
})
.withFailureHandler((err) => {
loadingMsg.innerHTML = "❌ Erreur : " + err;
loadingMsg.style.color = "#ef4444";
})
.processAutoScript(prompt);
}
function openPayment() {
// PayPal link (Replace with your actual URL)
const email = encodeURIComponent("<span id='user-email-placeholder'></span>");
window.open('https://www.paypal.com/ncp/payment/VOTRE_ID_PAYPAL?custom=' + email, '_blank');
}
function addMessage(text, type) {
const history = document.getElementById('chat-history');
const msgDiv = document.createElement('div');
msgDiv.className = 'message ' + type;
msgDiv.innerHTML = text;
history.appendChild(msgDiv);
history.scrollTop = history.scrollHeight;
return msgDiv;
}
function updateCredits(count) {
document.getElementById('credit-count').innerText = count;
}
// Chargement initial des crédits
window.onload = () => {
google.script.run.withSuccessHandler(updateCredits).getUserCredits();
};
</script>
</body>
</html>