-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
122 lines (113 loc) · 4.24 KB
/
index.js
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
/*
PC Simulator Save Editor is a free and open source save editor for PC Simulator.
Copyright (C) 2024 Mokka Chocolata
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Email: mokkachocolata@gmail.com
*/
// First time writing JS
window.onload=function() {
var textarea = document.getElementById("textarea");
var clicked = false;
window.onscroll = function() {scrollFunction()};
let gototopButton = document.getElementById("goToTop");
function scrollFunction() {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
gototopButton.style.display = "block";
} else {
gototopButton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
gototopButton.addEventListener("click", topFunction, false)
function copyToClipboard() {
navigator.clipboard.writeText(textarea.value);
}
function readSingleFile(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
textarea.value = decryptStr(contents);
clicked = false;
setTimeout(function(){
clicked = true;
}, 10);
}
reader.readAsText(file);
}
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}
}
// Decrypt provided string
function decryptStr(str) {
var key = 0x81;
var out = "";
for (let i = 0; i < str.length; i++) {
out += String.fromCharCode(str.charCodeAt(i) ^ key);
}
return out;
}
// Just basically a shortcut to the decryptStr function
function decrypt() {
textarea.value = decryptStr(textarea.value);
}
function down() {
download("Save.pc", decryptStr(textarea.value));
}
var open = document.getElementById("file-input");
open.addEventListener("click", readSingleFile, false);
var openDecrypt = document.getElementById("file-decrypttotxt");
// Decrypts the opened file, then saves it as a decrypted file
function decryptToTxt(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
download("Save.pc", decryptStr(contents));
};
reader.readAsText(file);
}
openDecrypt.addEventListener("click", decryptToTxt, false);
var button = document.getElementById("decrypt/encrypt");
button.addEventListener("click", decrypt, false);
var copy = document.getElementById("copy");
copy.addEventListener("click", copyToClipboard, false);
var openFile = document.getElementById("open");
openFile.addEventListener("click", function() {
open.click();
}, false);
var save = document.getElementById("save");
save.addEventListener("click", down, false);
var decrypttotxt = document.getElementById("decrypttotxt");
decrypttotxt.addEventListener("click", function() {
openDecrypt.click();
}, false);
}