added downloading saves + making it look good

This commit is contained in:
Sky 2023-05-22 15:30:43 -04:00
parent a66532f0d7
commit 99b38d19cd
4 changed files with 127 additions and 4 deletions

98
cookie.js Normal file
View File

@ -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);
});
}

View File

@ -16,7 +16,7 @@
<script src="base64.js"></script>
<script>
var VERSION = "BEST SITE EVER IN";
var VERSION = "2.053";
var BETA = 1;
var App = typeof App === "undefined" ? 0 : App;
</script>
@ -208,4 +208,4 @@
</div>
</div>
</body>
</html>
</html>

View File

@ -12,12 +12,20 @@
<meta name="description" content="Welcome to the one and only option for unblocked games. Welcome to e-gamepass." />
<meta name="author" content="Website Creator" />
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script src="cookie.js"></script>
</head>
<body>
<div class="content">
<input class="hiddenUpload" type="file" accept=".save" hidden>
<div class="title"><img src="favicon.png" style="width:4%;"><h2 style="font-size:50px">e-gamepass</h2></div>
<p><a href="bookmarklets.html">Click here for bookmarklets that you can use even if we get blocked!</a> - <a href="https://forms.gle/iBAbXvEDaYTLuEcdA">Want a game to be added? Suggest here!</a></p>
<p><a href="https://github.com/skysthelimitt/e-gamepass">Want to help me develop the website? Click here! (Must be on a device with GitHub unblocked)</a></p>
<p><a href="bookmarklets.html">Click here for bookmarklets that you can use even if we get blocked!</a> - <a href="https://forms.gle/iBAbXvEDaYTLuEcdA">Want a game to be added? Suggest here!</a> - <a href="https://github.com/skysthelimitt/e-gamepass">Want to help me develop the website? Click here!</a></p>
<p><a href="javascript:downloadMainSave()">Download Save</a> - <a href="javascript:uploadMainSave()">Upload Save</a></p><br>
<p class="uploadResult"></p>
<br>
<a href="adofai/index.html"><div class="game"><img src="adofai/icon.png" alt="ADOFAI Logo"><h1>ADOFAI</h1></div></a>
<a href="resent-client/index.html"><div class="game"><img src="resent-client/logo.png" alt="Resent Client Logo"><h1>Online Minecraft</h1></div></a>
<a href="offline-mc/index.html"><div class="game"><img src="offline-mc/logo.png" alt="Minecraft Logo"><h1>Offline Minecraft</h1></div></a>

View File

@ -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;