Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit aabde36

Browse files
i fucking did it
1 parent 8e01b4c commit aabde36

File tree

5 files changed

+349
-1
lines changed

5 files changed

+349
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# userlogins-for-fun-miles
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// Initialize Userbase
2+
userbase.init({ appId: '7cd8e25b-723d-4af7-8bdf-ef558bd0dfcc' }); // Replace with your Userbase app ID
3+
4+
let currentUser; // Variable to hold the current user object
5+
let isDatabaseOpen = false; // Flag to check if the database is open
6+
7+
document.getElementById('signup-form').addEventListener('submit', async (e) => {
8+
e.preventDefault();
9+
const username = document.getElementById('signup-username').value; // Email as username
10+
const password = document.getElementById('signup-password').value;
11+
12+
try {
13+
const user = await userbase.signUp({ username: username, password });
14+
alert('Signup successful!');
15+
} catch (error) {
16+
console.error('Signup error:', error);
17+
alert('Signup failed: ' + error.message);
18+
}
19+
});
20+
21+
document.getElementById('login-form').addEventListener('submit', async (e) => {
22+
e.preventDefault();
23+
const username = document.getElementById('login-username').value; // Email as username
24+
const password = document.getElementById('login-password').value;
25+
26+
try {
27+
currentUser = await userbase.signIn({
28+
username: username,
29+
password: password,
30+
rememberMe: 'none' // Do not remember the session
31+
});
32+
alert('Login successful!');
33+
document.getElementById('form-container').style.display = 'none';
34+
document.getElementById('note-management').style.display = 'block';
35+
36+
// Open the Userbase database
37+
await openUserbaseDatabase();
38+
} catch (error) {
39+
console.error('Login error:', error);
40+
alert('Login failed: ' + error.message);
41+
}
42+
});
43+
44+
// Function to check if user is logged in
45+
async function checkUserLoggedIn() {
46+
try {
47+
currentUser = await userbase.getUser();
48+
if (currentUser) {
49+
document.getElementById('form-container').style.display = 'none';
50+
document.getElementById('note-management').style.display = 'block';
51+
52+
// Open the Userbase database
53+
await openUserbaseDatabase();
54+
}
55+
} catch (error) {
56+
console.error('Error checking user login status:', error);
57+
}
58+
}
59+
60+
// Function to open Userbase database
61+
async function openUserbaseDatabase() {
62+
try {
63+
await userbase.openDatabase({
64+
databaseName: 'notes-database',
65+
changeHandler: function (items) {
66+
const notesList = document.getElementById('notes-list');
67+
notesList.innerHTML = ''; // Clear existing notes
68+
items.forEach(item => {
69+
const noteItem = document.createElement('li');
70+
noteItem.className = 'note-item';
71+
noteItem.textContent = item.item.text;
72+
73+
// Create delete button
74+
const deleteButton = document.createElement('button');
75+
deleteButton.textContent = 'Delete';
76+
deleteButton.style.marginLeft = '10px';
77+
deleteButton.onclick = () => deleteNote(item.itemId); // Bind delete function
78+
79+
noteItem.appendChild(deleteButton);
80+
notesList.appendChild(noteItem);
81+
});
82+
}
83+
});
84+
isDatabaseOpen = true;
85+
console.log('Database opened successfully.');
86+
} catch (error) {
87+
isDatabaseOpen = false;
88+
console.error('Error opening database:', error);
89+
}
90+
}
91+
92+
// Function to save note to Userbase
93+
async function saveNote() {
94+
if (!isDatabaseOpen) {
95+
alert('Database is not open. Please try again later.');
96+
return;
97+
}
98+
99+
const noteText = document.getElementById('note-input').value;
100+
if (!noteText) {
101+
alert('Please enter a note to save.');
102+
return;
103+
}
104+
105+
try {
106+
await userbase.insertItem({
107+
databaseName: 'notes-database',
108+
item: { text: noteText }
109+
});
110+
alert('Note saved successfully!');
111+
document.getElementById('note-input').value = ''; // Clear input
112+
} catch (error) {
113+
console.error('Error saving note:', error);
114+
alert('Failed to save note: ' + error.message);
115+
}
116+
}
117+
118+
// Function to delete a note from Userbase
119+
async function deleteNote(itemId) {
120+
if (!isDatabaseOpen) {
121+
alert('Database is not open. Please try again later.');
122+
return;
123+
}
124+
125+
try {
126+
await userbase.deleteItem({
127+
databaseName: 'notes-database',
128+
itemId: itemId
129+
});
130+
alert('Note deleted successfully!');
131+
} catch (error) {
132+
console.error('Error deleting note:', error);
133+
alert('Failed to delete note: ' + error.message);
134+
}
135+
}
136+
137+
// Function to log out the user
138+
async function logout() {
139+
try {
140+
await userbase.signOut(); // Sign out from Userbase
141+
currentUser = null; // Clear current user
142+
isDatabaseOpen = false; // Reset database open flag
143+
document.getElementById('form-container').style.display = 'block'; // Show login/signup forms
144+
document.getElementById('note-management').style.display = 'none'; // Hide note management
145+
alert('Logged out successfully!');
146+
} catch (error) {
147+
console.error('Logout error:', error);
148+
alert('Logout failed: ' + error.message);
149+
}
150+
}
151+
152+
// Function to save cookies to the cloud
153+
document.getElementById('save-cookies-cloud').addEventListener('click', async () => {
154+
if (!isDatabaseOpen) {
155+
alert('Database is not open. Please try again later.');
156+
return;
157+
}
158+
159+
try {
160+
// Clear existing items in the database
161+
await userbase.openDatabase({
162+
databaseName: 'notes-database',
163+
changeHandler: async function (items) {
164+
for (const item of items) {
165+
await userbase.deleteItem({
166+
databaseName: 'notes-database',
167+
itemId: item.itemId
168+
});
169+
}
170+
171+
// Save cookies to the cloud
172+
const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n');
173+
const chunkSize = 9000; // Set chunk size to be less than 10 KB
174+
for (let i = 0; i < cookies.length; i += chunkSize) {
175+
const chunk = cookies.substring(i, i + chunkSize);
176+
await userbase.insertItem({
177+
databaseName: 'notes-database',
178+
item: { text: chunk }
179+
});
180+
}
181+
}
182+
});
183+
} catch (error) {
184+
console.error('Error saving cookies to cloud:', error);
185+
alert('Failed to save cookies to cloud: ' + error.message);
186+
}
187+
});
188+
189+
// Function to load cookies from the cloud
190+
document.getElementById('load-cookies-cloud').addEventListener('click', async () => {
191+
if (!isDatabaseOpen) {
192+
alert('Database is not open. Please try again later.');
193+
return;
194+
}
195+
196+
try {
197+
await userbase.openDatabase({
198+
databaseName: 'notes-database',
199+
changeHandler: function (items) {
200+
const cookies = items.map(item => item.item.text).join('\n');
201+
document.cookie = cookies.split('\n').map(cookie => encodeURIComponent(cookie.trim())).join('; ');
202+
alert('Cookies loaded from cloud successfully!');
203+
}
204+
});
205+
} catch (error) {
206+
console.error('Error loading cookies from cloud:', error);
207+
alert('Failed to load cookies from cloud: ' + error.message);
208+
}
209+
});
210+
211+
// Function to display cookies
212+
function displayCookies() {
213+
const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n');
214+
document.getElementById('cookies-display').textContent = cookies;
215+
document.getElementById('cookies-input').value = cookies;
216+
}
217+
218+
// Function to save cookies from the textarea
219+
document.getElementById('save-cookies').addEventListener('click', () => {
220+
const cookies = document.getElementById('cookies-input').value.split('\n');
221+
cookies.forEach(cookie => {
222+
document.cookie = encodeURIComponent(cookie.trim());
223+
});
224+
alert('Cookies updated!');
225+
displayCookies();
226+
});
227+
228+
// Event listeners for buttons
229+
document.getElementById('save-note').addEventListener('click', saveNote);
230+
document.getElementById('logout-button').addEventListener('click', logout);
231+
232+
// Check if user is logged in when the page loads
233+
window.onload = checkUserLoggedIn;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Notes Management</title>
7+
<link rel="stylesheet" href="styles.css">
8+
<script type="text/javascript" src="https://sdk.userbase.com/2/userbase.js"></script>
9+
</head>
10+
<body onload="checkUserLoggedIn()">
11+
<div class="container">
12+
<h1>Notes Management</h1>
13+
<div id="form-container">
14+
<form id="signup-form">
15+
<h2>Sign Up</h2>
16+
<input type="text" id="signup-username" placeholder="Username (Email)" required>
17+
<input type="password" id="signup-password" placeholder="Password" required>
18+
<button type="submit">Sign Up</button>
19+
</form>
20+
<form id="login-form">
21+
<h2>Login</h2>
22+
<input type="text" id="login-username" placeholder="Username (Email)" required>
23+
<input type="password" id="login-password" placeholder="Password" required>
24+
<button type="submit">Login</button>
25+
</form>
26+
</div>
27+
<div id="note-management" style="display: none;">
28+
<h2>Note Management</h2>
29+
<input type="text" id="note-input" placeholder="Write your note here..." />
30+
<button id="logout-button">Logout</button>
31+
<ul id="notes-list" style="margin-top: 20px;"></ul>
32+
<div id="cookies-container">
33+
<h2>Cookies</h2>
34+
<p id="cookies-display"></p>
35+
<button id="save-cookies-cloud">Save Cookies to Cloud</button>
36+
<button id="load-cookies-cloud">Load Cookies from Cloud</button>
37+
</div>
38+
</div>
39+
</div>
40+
<script src="app.js"></script>
41+
</body>
42+
</html>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
background-color: #f4f4f4;
4+
margin: 0;
5+
padding: 20px;
6+
}
7+
8+
.container {
9+
max-width: 600px;
10+
margin: auto;
11+
background: white;
12+
padding: 20px;
13+
border-radius: 5px;
14+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
15+
}
16+
17+
h1, h2 {
18+
color: #333;
19+
}
20+
21+
form {
22+
margin-bottom: 20px;
23+
}
24+
25+
input[type="text"],
26+
input[type="password"] {
27+
width: 100%;
28+
padding: 10px;
29+
margin: 10px 0;
30+
border: 1px solid #ccc;
31+
border-radius: 4px;
32+
}
33+
34+
button {
35+
padding: 10px 15px;
36+
background-color: #5cb85c;
37+
color: white;
38+
border: none;
39+
border-radius: 4px;
40+
cursor: pointer;
41+
}
42+
43+
button:hover {
44+
background-color: #4cae4c;
45+
}
46+
47+
#notes-list {
48+
list-style-type: none;
49+
padding: 0;
50+
}
51+
52+
.note-item {
53+
display: flex;
54+
justify-content: space-between;
55+
align-items: center;
56+
background: #e9ecef;
57+
padding: 10px;
58+
margin: 5px 0;
59+
border-radius: 4px;
60+
}
61+
62+
.note-item button {
63+
background-color: #d9534f;
64+
color: white;
65+
border: none;
66+
border-radius: 4px;
67+
cursor: pointer;
68+
}
69+
70+
.note-item button:hover {
71+
background-color: #c9302c;
72+
}

script2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const mainContentData = [
8787
{
8888
name: "save to cloud",
8989
image: "/WebGames-master/WebGames-master/assets/save-to-cloud-2.png",
90-
link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/userlogins-for-fun-miles-main/index.html",
90+
link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html",
9191
},
9292
];
9393
mainContentData.forEach(item => {

0 commit comments

Comments
 (0)