From 99b38d19cd2b86f713f2a8999991e424eea6698e Mon Sep 17 00:00:00 2001 From: Sky Date: Mon, 22 May 2023 15:30:43 -0400 Subject: [PATCH] added downloading saves + making it look good --- cookie.js | 98 ++++++++++++++++++++++++++++++++++++++++ cookieclicker/index.html | 4 +- index.html | 12 ++++- style.css | 17 +++++++ 4 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 cookie.js diff --git a/cookie.js b/cookie.js new file mode 100644 index 00000000..efc49d48 --- /dev/null +++ b/cookie.js @@ -0,0 +1,98 @@ +function getMainSave() { + var mainSave = {}; + // List of items in localStorage that should not be saved + var localStorageDontSave = ['hjgkkkhjgasdgasjydguyaiw']; + + // Convert localStorage to an array of key-value pairs and remove the items that should not be saved + localStorageSave = Object.entries(localStorage); + + for (let entry in localStorageSave) { + if (localStorageDontSave.includes(localStorageSave[entry][0])) { + localStorageSave.splice(entry, 1); + } + } + + // Convert the localStorage array to a base64-encoded JSON string + localStorageSave = btoa(JSON.stringify(localStorageSave)); + + // Add the localStorage data to the mainSave object + mainSave.localStorage = localStorageSave; + + // Get the cookies data and add it to the mainSave object + cookiesSave = document.cookie; + cookiesSave = btoa(cookiesSave); + mainSave.cookies = cookiesSave; + + // Convert the mainSave object to a base64-encoded JSON string + mainSave = btoa(JSON.stringify(mainSave)); + + // Encrypt the mainSave data using AES encryption with the key 'save' + mainSave = CryptoJS.AES.encrypt(mainSave, 'egamepass').toString(); + + // Return the encrypted mainSave data + return mainSave; +} + +// Function to download the main save data as a file +function downloadMainSave() { + var data = new Blob([getMainSave()]); + var dataURL = URL.createObjectURL(data); + + var fakeElement = document.createElement('a'); + fakeElement.href = dataURL; + fakeElement.download = 'your.e-gamepass.save'; + fakeElement.click(); + URL.revokeObjectURL(dataURL); + alert("Make sure to keep the file that was just downloaded so you can use it to restore your progress in games later.") +} + +// Function to get the main save data from an uploaded file +function getMainSaveFromUpload(data) { + // Decrypt the uploaded data using AES decryption with the key 'save' + data = CryptoJS.AES.decrypt(data, 'egamepass').toString(CryptoJS.enc.Utf8); + + // Parse the decrypted data as JSON + var mainSave = JSON.parse(atob(data)); + var mainLocalStorageSave = JSON.parse(atob(mainSave.localStorage)); + var cookiesSave = atob(mainSave.cookies); + + // Set the items in localStorage using the uploaded data + for (let item of mainLocalStorageSave) { + localStorage.setItem(item[0], item[1]); + } + + // Set the cookies using the uploaded data + document.cookie = cookiesSave; +} + +// Function to handle the file upload +function uploadMainSave() { + var hiddenUpload = document.querySelector('.hiddenUpload'); + hiddenUpload.click(); + + // Listen for the change event on the file input element + hiddenUpload.addEventListener('change', function (e) { + var files = e.target.files; + var file = files[0]; + if (!file) { + return; + } + + // Read the contents of the uploaded file as text and call getMainSaveFromUpload with the result + var reader = new FileReader(); + + reader.onload = function (e) { + getMainSaveFromUpload(e.target.result); + + // Show a success message to the user + var uploadResult = document.querySelector('.uploadResult'); + uploadResult.innerText = 'Uploaded save!'; + uploadResult.style.display = 'initial'; + setTimeout(function () { + uploadResult.style.display = 'none'; + }, 3000); + }; + + reader.readAsText(file); + }); +} diff --git a/cookieclicker/index.html b/cookieclicker/index.html index a5b9276b..5eef730d 100644 --- a/cookieclicker/index.html +++ b/cookieclicker/index.html @@ -16,7 +16,7 @@ @@ -208,4 +208,4 @@ - \ No newline at end of file + diff --git a/index.html b/index.html index 26a6a1e0..96822d96 100644 --- a/index.html +++ b/index.html @@ -12,12 +12,20 @@ + +
+ + + +

e-gamepass

-

Click here for bookmarklets that you can use even if we get blocked! - Want a game to be added? Suggest here!

-

Want to help me develop the website? Click here! (Must be on a device with GitHub unblocked)

+

Click here for bookmarklets that you can use even if we get blocked! - Want a game to be added? Suggest here! - Want to help me develop the website? Click here!

+

Download Save - Upload Save


+

+
ADOFAI Logo

ADOFAI

Resent Client Logo

Online Minecraft

Minecraft Logo

Offline Minecraft

diff --git a/style.css b/style.css index d235b139..c9ffe3f6 100644 --- a/style.css +++ b/style.css @@ -13,6 +13,23 @@ html { margin: 0 auto; } +button { + background-color: rgba(83, 141, 175, 0); + color: #8daad8; + border: 2.5px solid rgba(0,0,0,0); + border-radius: 10px; +padding: 5px 13px; + margin-bottom: 6px; + transition-duration: 0.45s; + font-size: 20px; + color: #6983da; + font-family: "Share Tech Mono", monospace; + text-underline-position: under; +} +button:hover { + cursor:pointer; +} + h2 { font-size: 42px; color: #0073e6;