-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
225 lines (181 loc) · 6.22 KB
/
script.js
File metadata and controls
225 lines (181 loc) · 6.22 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Basit kullanıcı sistemi (localStorage tabanlı)
// Moderatör hesabı: EmirSeyfOS
const MOD_USERNAME = "lattesiber";
const usernameInput = document.getElementById("usernameInput");
const passwordInput = document.getElementById("passwordInput");
const loginBtn = document.getElementById("loginBtn");
const registerBtn = document.getElementById("registerBtn");
const currentUserLabel = document.getElementById("currentUser");
const moderatorPanel = document.getElementById("moderatorPanel");
const modName = document.getElementById("modName");
const projectForm = document.getElementById("projectForm");
const projectsList = document.getElementById("projectsList");
let currentUser = null;
let users = {};
let projects = [];
// Sayfa açıldığında verileri yükle
window.addEventListener("DOMContentLoaded", () => {
const savedUsers = localStorage.getItem("pk_users");
if (savedUsers) users = JSON.parse(savedUsers);
const savedUser = localStorage.getItem("pk_currentUser");
if (savedUser) setUser(savedUser);
const savedProjects = localStorage.getItem("pk_projects");
if (savedProjects) {
projects = JSON.parse(savedProjects);
} else {
projects = [
{
name: "Scaty Tanıtım",
url: "https://scratch.mit.edu/projects/000000000",
description: "Scaty tanıtımı url'yi js'den değiştir",
author: "Admin"
}
];
saveProjects();
}
renderProjects();
});
// Kullanıcı kaydı
registerBtn.addEventListener("click", () => {
const username = usernameInput.value.trim();
const password = passwordInput.value.trim();
if (!username || !password) {
alert("Kullanıcı adı ve şifre boş olamaz.");
return;
}
if (users[username]) {
alert("Bu kullanıcı adı zaten kayıtlı.");
return;
}
users[username] = { password };
saveUsers();
alert("Kayıt başarılı! Artık giriş yapabilirsin.");
});
// Giriş
loginBtn.addEventListener("click", () => {
const username = usernameInput.value.trim();
const password = passwordInput.value.trim();
if (!username || !password) {
alert("Kullanıcı adı ve şifre gir.");
return;
}
if (!users[username]) {
alert("Böyle bir kullanıcı yok. Önce kayıt ol.");
return;
}
if (users[username].password !== password) {
alert("Şifre yanlış.");
return;
}
setUser(username);
});
// Kullanıcı ayarla
function setUser(username) {
currentUser = username;
currentUserLabel.textContent = `Giriş yapıldı: ${username}`;
usernameInput.value = "";
passwordInput.value = "";
checkModerator();
localStorage.setItem("pk_currentUser", username);
}
// Moderatör kontrolü
function checkModerator() {
if (currentUser === MOD_USERNAME) {
moderatorPanel.style.display = "block";
modName.textContent = currentUser;
} else {
moderatorPanel.style.display = "none";
modName.textContent = "";
}
}
// Kullanıcıları kaydet
function saveUsers() {
localStorage.setItem("pk_users", JSON.stringify(users));
}
// Proje gönderme
projectForm.addEventListener("submit", (e) => {
e.preventDefault();
if (!currentUser) {
alert("Proje paylaşmak için giriş yapmalısın.");
return;
}
const name = document.getElementById("projectName").value.trim();
const url = document.getElementById("projectUrl").value.trim();
const description = document.getElementById("projectDescription").value.trim();
if (!name || !url || !description) {
alert("Tüm alanları doldur.");
return;
}
const newProject = {
name,
url,
description,
author: currentUser
};
projects.unshift(newProject);
saveProjects();
renderProjects();
projectForm.reset();
});
// Projeleri kaydet
function saveProjects() {
localStorage.setItem("pk_projects", JSON.stringify(projects));
}
// Projeleri listele
function renderProjects() {
projectsList.innerHTML = "";
if (projects.length === 0) {
projectsList.innerHTML = "<p>Henüz proje yok.</p>";
return;
}
projects.forEach((project, index) => {
const card = document.createElement("div");
card.className = "project-card";
const header = document.createElement("div");
header.className = "project-card-header";
const title = document.createElement("div");
title.className = "project-title";
title.textContent = project.name;
const user = document.createElement("div");
user.className = "project-user";
user.textContent = `Paylaşan: ${project.author}`;
header.appendChild(title);
header.appendChild(user);
const desc = document.createElement("div");
desc.className = "project-desc";
desc.textContent = project.description;
const link = document.createElement("div");
link.className = "project-link";
const a = document.createElement("a");
a.href = project.url;
a.target = "_blank";
// Scratch URL → TurboWarp Player URL
const projectId = project.url.split("/projects/")[1].replace("/", "");
a.href = `https://turbowarp.org/${projectId}/embed`;
link.appendChild(a);
card.appendChild(header);
card.appendChild(desc);
card.appendChild(link);
// Moderatör silme butonu
if (currentUser === MOD_USERNAME) {
const del = document.createElement("button");
del.textContent = "Sil (Mod)";
del.style.marginTop = "6px";
del.style.background = "#dc2626";
del.style.color = "white";
del.style.border = "none";
del.style.padding = "4px 8px";
del.style.borderRadius = "4px";
del.style.cursor = "pointer";
del.addEventListener("click", () => {
if (confirm("Bu projeyi silmek istiyor musun?")) {
projects.splice(index, 1);
saveProjects();
renderProjects();
}
});
card.appendChild(del);
}
projectsList.appendChild(card);
});
}