-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathadmin.html
More file actions
204 lines (176 loc) · 6.02 KB
/
Copy pathadmin.html
File metadata and controls
204 lines (176 loc) · 6.02 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel</title>
<style>
body {
font-family: "Manrope", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
font-weight: 500;
margin: 0;
padding: 20px;
background-color: #555555;
color: #fff;
}
h1 {
text-align: center;
color: #fff;
}
.admin-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
}
.admin-section {
background-color: #444444;
padding: 20px;
border-radius: 10px;
width: 300px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
}
.admin-section h2 {
margin-top: 0;
font-size: 1.5rem;
}
label {
display: block;
margin-bottom: 10px;
color: #fff;
}
input, button {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
font-size: 16px;
}
input[type="color"] {
padding: 0;
height: 50px;
}
button {
background-color: #4caf50;
color: white;
cursor: pointer;
font-size: 18px;
}
button:hover {
background-color: #45a049;
}
.error {
color: red;
margin-bottom: 20px;
}
.success {
color: green;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>Admin Panel</h1>
<div class="admin-container">
<!-- Add Badge Section -->
<div class="admin-section">
<h2>Add User Badge</h2>
<div id="add-badge-error" class="error" style="display:none;"></div>
<div id="add-badge-success" class="success" style="display:none;"></div>
<label for="badge-username">Enter Username:</label>
<input type="text" id="badge-username" placeholder="Enter current username">
<label for="badge-text">Badge Text:</label>
<input type="text" id="badge-text" placeholder="Enter badge text (e.g., VIP, Owner)">
<label for="badge-color">Choose Badge Color:</label>
<input type="color" id="badge-color" value="#FFD700">
<button id="add-badge-button">Add Badge</button>
</div>
<!-- Force Run Workflows Section -->
<div class="admin-section">
<h2>Force Run Workflows</h2>
<div id="workflow-error" class="error" style="display:none;"></div>
<div id="workflow-success" class="success" style="display:none;"></div>
<button id="run-workflows-button">Run Workflows</button>
</div>
</div>
<script>
// GitHub Personal Access Token (PAT)
const githubToken = "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"; // Replace with your GitHub PAT
// Function to trigger GitHub workflows
async function triggerWorkflows() {
const workflows = [
"main.yaml", // Ensure correct file extension
"static.yml",
"sync.yml",
];
const owner = "jman1593"; // Replace with your GitHub username
const repo = "jman1593.github.io"; // Replace with your repository name
try {
for (const workflow of workflows) {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflow}/dispatches`,
{
method: "POST",
headers: {
"Authorization": `Bearer ${githubToken}`,
"Accept": "application/vnd.github.v3+json",
"Content-Type": "application/json",
},
body: JSON.stringify({
ref: "master", // Replace with the branch name to run the workflows
}),
}
);
if (!response.ok) {
const errorDetails = await response.json();
console.error("GitHub API error:", errorDetails);
throw new Error(`Failed to trigger workflow: ${workflow}`);
}
}
// Display success message
document.getElementById("workflow-success").textContent =
"Workflows triggered successfully!";
document.getElementById("workflow-success").style.display = "block";
document.getElementById("workflow-error").style.display = "none";
} catch (error) {
// Display error message
console.error("Error triggering workflows:", error);
document.getElementById("workflow-error").textContent =
"Error triggering workflows: " + error.message;
document.getElementById("workflow-error").style.display = "block";
document.getElementById("workflow-success").style.display = "none";
}
}
// Add Badge Functionality
async function addBadge() {
const username = document.getElementById("badge-username").value;
const badgeText = document.getElementById("badge-text").value;
const badgeColor = document.getElementById("badge-color").value;
try {
if (!username || !badgeText) {
throw new Error("Please fill out all fields.");
}
// Simulate adding a badge (customize as per your backend/API needs)
console.log(`Badge added for ${username}: ${badgeText} (${badgeColor})`);
document.getElementById("add-badge-success").textContent =
`Badge '${badgeText}' added for user '${username}'!`;
document.getElementById("add-badge-success").style.display = "block";
document.getElementById("add-badge-error").style.display = "none";
} catch (error) {
console.error("Error adding badge:", error);
document.getElementById("add-badge-error").textContent = error.message;
document.getElementById("add-badge-error").style.display = "block";
document.getElementById("add-badge-success").style.display = "none";
}
}
// Event Listeners
document
.getElementById("run-workflows-button")
.addEventListener("click", triggerWorkflows);
document
.getElementById("add-badge-button")
.addEventListener("click", addBadge);
</script>
</body>
</html>