From aabde36eeb57d01dead169aa2edf6faf75229ee0 Mon Sep 17 00:00:00 2001 From: mileswa1q22 Date: Wed, 26 Feb 2025 19:13:19 +0000 Subject: [PATCH] i fucking did it --- .../userlogins-for-fun-miles-main/README.md | 1 + .../userlogins-for-fun-miles-main/app.js | 233 ++++++++++++++++++ .../userlogins-for-fun-miles-main/index.html | 42 ++++ .../userlogins-for-fun-miles-main/styles.css | 72 ++++++ script2.js | 2 +- 5 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 WebGames-master/WebGames-master/userlogins-for-fun-miles-main/README.md create mode 100644 WebGames-master/WebGames-master/userlogins-for-fun-miles-main/app.js create mode 100644 WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html create mode 100644 WebGames-master/WebGames-master/userlogins-for-fun-miles-main/styles.css diff --git a/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/README.md b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/README.md new file mode 100644 index 00000000..9ce523d1 --- /dev/null +++ b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/README.md @@ -0,0 +1 @@ +# userlogins-for-fun-miles \ No newline at end of file diff --git a/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/app.js b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/app.js new file mode 100644 index 00000000..4af9258d --- /dev/null +++ b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/app.js @@ -0,0 +1,233 @@ +// Initialize Userbase +userbase.init({ appId: '7cd8e25b-723d-4af7-8bdf-ef558bd0dfcc' }); // Replace with your Userbase app ID + +let currentUser; // Variable to hold the current user object +let isDatabaseOpen = false; // Flag to check if the database is open + +document.getElementById('signup-form').addEventListener('submit', async (e) => { + e.preventDefault(); + const username = document.getElementById('signup-username').value; // Email as username + const password = document.getElementById('signup-password').value; + + try { + const user = await userbase.signUp({ username: username, password }); + alert('Signup successful!'); + } catch (error) { + console.error('Signup error:', error); + alert('Signup failed: ' + error.message); + } +}); + +document.getElementById('login-form').addEventListener('submit', async (e) => { + e.preventDefault(); + const username = document.getElementById('login-username').value; // Email as username + const password = document.getElementById('login-password').value; + + try { + currentUser = await userbase.signIn({ + username: username, + password: password, + rememberMe: 'none' // Do not remember the session + }); + alert('Login successful!'); + document.getElementById('form-container').style.display = 'none'; + document.getElementById('note-management').style.display = 'block'; + + // Open the Userbase database + await openUserbaseDatabase(); + } catch (error) { + console.error('Login error:', error); + alert('Login failed: ' + error.message); + } +}); + +// Function to check if user is logged in +async function checkUserLoggedIn() { + try { + currentUser = await userbase.getUser(); + if (currentUser) { + document.getElementById('form-container').style.display = 'none'; + document.getElementById('note-management').style.display = 'block'; + + // Open the Userbase database + await openUserbaseDatabase(); + } + } catch (error) { + console.error('Error checking user login status:', error); + } +} + +// Function to open Userbase database +async function openUserbaseDatabase() { + try { + await userbase.openDatabase({ + databaseName: 'notes-database', + changeHandler: function (items) { + const notesList = document.getElementById('notes-list'); + notesList.innerHTML = ''; // Clear existing notes + items.forEach(item => { + const noteItem = document.createElement('li'); + noteItem.className = 'note-item'; + noteItem.textContent = item.item.text; + + // Create delete button + const deleteButton = document.createElement('button'); + deleteButton.textContent = 'Delete'; + deleteButton.style.marginLeft = '10px'; + deleteButton.onclick = () => deleteNote(item.itemId); // Bind delete function + + noteItem.appendChild(deleteButton); + notesList.appendChild(noteItem); + }); + } + }); + isDatabaseOpen = true; + console.log('Database opened successfully.'); + } catch (error) { + isDatabaseOpen = false; + console.error('Error opening database:', error); + } +} + +// Function to save note to Userbase +async function saveNote() { + if (!isDatabaseOpen) { + alert('Database is not open. Please try again later.'); + return; + } + + const noteText = document.getElementById('note-input').value; + if (!noteText) { + alert('Please enter a note to save.'); + return; + } + + try { + await userbase.insertItem({ + databaseName: 'notes-database', + item: { text: noteText } + }); + alert('Note saved successfully!'); + document.getElementById('note-input').value = ''; // Clear input + } catch (error) { + console.error('Error saving note:', error); + alert('Failed to save note: ' + error.message); + } +} + +// Function to delete a note from Userbase +async function deleteNote(itemId) { + if (!isDatabaseOpen) { + alert('Database is not open. Please try again later.'); + return; + } + + try { + await userbase.deleteItem({ + databaseName: 'notes-database', + itemId: itemId + }); + alert('Note deleted successfully!'); + } catch (error) { + console.error('Error deleting note:', error); + alert('Failed to delete note: ' + error.message); + } +} + +// Function to log out the user +async function logout() { + try { + await userbase.signOut(); // Sign out from Userbase + currentUser = null; // Clear current user + isDatabaseOpen = false; // Reset database open flag + document.getElementById('form-container').style.display = 'block'; // Show login/signup forms + document.getElementById('note-management').style.display = 'none'; // Hide note management + alert('Logged out successfully!'); + } catch (error) { + console.error('Logout error:', error); + alert('Logout failed: ' + error.message); + } +} + +// Function to save cookies to the cloud +document.getElementById('save-cookies-cloud').addEventListener('click', async () => { + if (!isDatabaseOpen) { + alert('Database is not open. Please try again later.'); + return; + } + + try { + // Clear existing items in the database + await userbase.openDatabase({ + databaseName: 'notes-database', + changeHandler: async function (items) { + for (const item of items) { + await userbase.deleteItem({ + databaseName: 'notes-database', + itemId: item.itemId + }); + } + + // Save cookies to the cloud + const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n'); + const chunkSize = 9000; // Set chunk size to be less than 10 KB + for (let i = 0; i < cookies.length; i += chunkSize) { + const chunk = cookies.substring(i, i + chunkSize); + await userbase.insertItem({ + databaseName: 'notes-database', + item: { text: chunk } + }); + } + } + }); + } catch (error) { + console.error('Error saving cookies to cloud:', error); + alert('Failed to save cookies to cloud: ' + error.message); + } +}); + +// Function to load cookies from the cloud +document.getElementById('load-cookies-cloud').addEventListener('click', async () => { + if (!isDatabaseOpen) { + alert('Database is not open. Please try again later.'); + return; + } + + try { + await userbase.openDatabase({ + databaseName: 'notes-database', + changeHandler: function (items) { + const cookies = items.map(item => item.item.text).join('\n'); + document.cookie = cookies.split('\n').map(cookie => encodeURIComponent(cookie.trim())).join('; '); + alert('Cookies loaded from cloud successfully!'); + } + }); + } catch (error) { + console.error('Error loading cookies from cloud:', error); + alert('Failed to load cookies from cloud: ' + error.message); + } +}); + +// Function to display cookies +function displayCookies() { + const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n'); + document.getElementById('cookies-display').textContent = cookies; + document.getElementById('cookies-input').value = cookies; +} + +// Function to save cookies from the textarea +document.getElementById('save-cookies').addEventListener('click', () => { + const cookies = document.getElementById('cookies-input').value.split('\n'); + cookies.forEach(cookie => { + document.cookie = encodeURIComponent(cookie.trim()); + }); + alert('Cookies updated!'); + displayCookies(); +}); + +// Event listeners for buttons +document.getElementById('save-note').addEventListener('click', saveNote); +document.getElementById('logout-button').addEventListener('click', logout); + +// Check if user is logged in when the page loads +window.onload = checkUserLoggedIn; diff --git a/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html new file mode 100644 index 00000000..ffeeec0f --- /dev/null +++ b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html @@ -0,0 +1,42 @@ + + + + + + Notes Management + + + + +
+

Notes Management

+
+
+

Sign Up

+ + + +
+
+

Login

+ + + +
+
+ +
+ + + \ No newline at end of file diff --git a/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/styles.css b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/styles.css new file mode 100644 index 00000000..26bef55c --- /dev/null +++ b/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/styles.css @@ -0,0 +1,72 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + margin: 0; + padding: 20px; +} + +.container { + max-width: 600px; + margin: auto; + background: white; + padding: 20px; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1, h2 { + color: #333; +} + +form { + margin-bottom: 20px; +} + +input[type="text"], +input[type="password"] { + width: 100%; + padding: 10px; + margin: 10px 0; + border: 1px solid #ccc; + border-radius: 4px; +} + +button { + padding: 10px 15px; + background-color: #5cb85c; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +button:hover { + background-color: #4cae4c; +} + +#notes-list { + list-style-type: none; + padding: 0; +} + +.note-item { + display: flex; + justify-content: space-between; + align-items: center; + background: #e9ecef; + padding: 10px; + margin: 5px 0; + border-radius: 4px; +} + +.note-item button { + background-color: #d9534f; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.note-item button:hover { + background-color: #c9302c; +} diff --git a/script2.js b/script2.js index a2dc9521..f9e0b804 100644 --- a/script2.js +++ b/script2.js @@ -87,7 +87,7 @@ const mainContentData = [ { name: "save to cloud", image: "/WebGames-master/WebGames-master/assets/save-to-cloud-2.png", - link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/userlogins-for-fun-miles-main/index.html", + link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html", }, ]; mainContentData.forEach(item => {