-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnote-script.js
More file actions
276 lines (276 loc) · 10.3 KB
/
note-script.js
File metadata and controls
276 lines (276 loc) · 10.3 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
function getVarParse(){
var getVars = new Array();
var locvartemp = ( window.location.href.indexOf( "?" ) + 1 ) ? window.location.href.substr( window.location.href.indexOf( "?" ) + 1 ) : "";
locvartemp = locvartemp.split( "&" );
for( var x = 0; x < locvartemp.length; x++ ) {
var lvTempVar = locvartemp[x].split( "=" );
getVars[ unescape( lvTempVar[0] ) ] = unescape( lvTempVar[1] );
}
return getVars;
}
function setCookie(cname, cvalue, exdays) {
if (exdays != undefined) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + encodeURIComponent(cvalue) + ";" + expires + ";path=/";
}
else {
document.cookie = cname + "=" + cvalue + ";path=/";
}
}
function p(raw){
if (raw == undefined) {
return "Paige" + document.getElementById("pn").innerHTML;
}
else {
return parseInt(document.getElementById("pn").innerHTML);
}
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return decodeURIComponent(c.substring(name.length, c.length));
}
}
return "";
}
function deleteCookie(cname){
document.cookie = cname +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
function updateCookies(){
var button = document.getElementById("KitKat Bar");
button.innerHTML = "Saving↻..."
setCookie(p(),document.getElementById("Paige").value,36500);
button.innerHTML = "Saved!"
setTimeout(function(){document.getElementById("KitKat Bar").innerHTML = "💾Save💾";}, 2000);
}
function DAT(){
var body = "<html>";
var counter = 1;
while (true) {
if (getCookie("Paige" + counter.toString()) !== ""){
body += "<h1>Page " + counter.toString() + "</h1><p>" + getCookie("Paige" + counter.toString()) + "</p>";
//alert(getCookie("Paige" + counter.toString()))
}
else{
break
}
counter++;
};
body += "</html>"
//var data = new Blob([body], {type: 'text/plain'});
//var url = window.URL.createObjectURL(data);
//document.location.href = url;
download(new Blob([body]),"KindleNotepadCreation.html","text/plain");
}
function sendDataJSON(){
var url = prompt("What's your data url?");
if (url !== null && url !== ""){
var xhttp = new XMLHttpRequest();
var body = "{";
var counter = 1;
while (true) {
if (getCookie("Paige" + counter.toString()) !== ""){
if (counter > 1) {
body += ","
}
var ckey = "Page " + counter.toString()
var cval = getCookie("Paige" + counter.toString())
body += "\"" + ckey + "\":\"" + cval + "\"";
//alert(getCookie("Paige" + counter.toString()))
}
else{
break
}
counter++;
};
body += "}"
alert(body);
var outputCode;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//alert(this.status.toString());
//alert(this.response);
//alert(xhttp.getAllResponseHeaders());
//outputCode = this.getResponseHeader("Location");
//alert("Your output has gone to: " + outputCode);
alert("Your Kindle Notepad Creation has been sent!");
}
};
xhttp.open("PUT",url);
xhttp.setRequestHeader("Content-type","application/json");
xhttp.setRequestHeader("Accept","application/json");
xhttp.setRequestHeader("Access-Control-Expose-Headers","Location");
xhttp.send(body);
}
else{
alert("Nothing has been sent...");
}
}
function csendDataJSON(){
var xhttp = new XMLHttpRequest();
var body = "{";
var counter = 1;
while (true) {
if (getCookie("Paige" + counter.toString()) !== ""){
if (counter > 1) {
body += ","
}
var ckey = "Page " + counter.toString()
var cval = getCookie("Paige" + counter.toString())
body += "\"" + ckey + "\":\"" + cval + "\"";
//alert(getCookie("Paige" + counter.toString()))
}
else{
break
}
counter++;
}
body += "}"
alert(body);
var outputCode;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 201) {
//alert(this.status.toString());
//alert(this.response);
//alert(xhttp.getAllResponseHeaders());
outputCode = this.getResponseHeader("Location");
alert("Your Kindle Notepad creation has gone to: " + outputCode);
}
};
xhttp.open("POST","https://jsonblob.com/api/jsonBlob");
xhttp.setRequestHeader("Content-type","application/json");
xhttp.setRequestHeader("Accept","application/json");
xhttp.setRequestHeader("Access-Control-Expose-Headers","Location");
xhttp.send(body);
}
function receiveDataJSON(){
var axhttp = new XMLHttpRequest();
axhttp.open("POST", "https://jsonblob.com/api/jsonBlob", false);
axhttp.setRequestHeader("Content-type","application/json");
axhttp.setRequestHeader("Accept","application/json");
axhttp.send('{"NoData":"Yep nothing"}');
var loc = axhttp.getResponseHeader("Location");
var locconf = confirm("Send data to:" + loc + "\nDo not press \"OK\" until you have sent your notepad from the Kindle end!\n(Press cancel to cancel)");
if (locconf) {
var url = loc;
}
else {
var url = null;
}
//var url = prompt("What's your data url?");
if (url !== "" && url !== null){
var xhttp = new XMLHttpRequest();
var outputCode;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status.toString()[0] == "2") {
outputCode = this.response;
outputCode = JSON.parse(outputCode);
if (confirm("Received: " + this.response + "\nWould you like to import it?")){
clearInterval(autoSave);
var x;
for (x in outputCode) {
setCookie(x.replace("Page ","Paige"), outputCode[x])
}
var cxhttp = new XMLHttpRequest();
cxhttp.open("DELETE", url);
cxhttp.send();
alert("Transfer complete!\n(Autosave has been stopped. To resume autosave and get the correct information for the current page, refresh the page or change pages.)")
}
else{
alert("Nothing has been changed...");
}
}
};
xhttp.open("GET",url);
xhttp.setRequestHeader("Content-type","application/json");
xhttp.setRequestHeader("Accept","application/json");
xhttp.send();
}
else{
var cxhttp = new XMLHttpRequest();
cxhttp.open("DELETE", loc);
cxhttp.send();
alert("Nothing's been changed...");
}
}
function kreceiveDataJSON(){
var url = prompt("What's your data url?");
if (url !== "" && url !== null){
var xhttp = new XMLHttpRequest();
var outputCode;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status.toString()[0] == "2") {
outputCode = this.response;
outputCode = JSON.parse(outputCode);
if (confirm("Received: " + this.response + "\nWould you like to import it?")){
clearInterval(autoSave);
var x;
for (x in outputCode) {
setCookie(x.replace("Page ","Paige"), outputCode[x])
}
var cxhttp = new XMLHttpRequest();
cxhttp.open("DELETE", url);
cxhttp.send();
alert("Transfer complete!\n(Autosave has been stopped. To resume autosave and get the correct information for the current page, refresh the page or change pages.)")
}
else{
alert("Nothing has been changed...");
}
}
};
xhttp.open("GET",url);
xhttp.setRequestHeader("Content-type","application/json");
xhttp.setRequestHeader("Accept","application/json");
xhttp.send();
}
else{
var cxhttp = new XMLHttpRequest();
cxhttp.open("DELETE", loc);
cxhttp.send();
alert("Nothing's been changed...");
}
}
var addvar = getVarParse();
onload = function(){
console.log(addvar);
if (addvar["p"] != undefined){
document.getElementById("pn").innerHTML = addvar["p"];
}
if (p(1) == 1){
document.getElementById("back").disabled = "true";
}
console.log(getCookie(p()));
document.getElementById("Paige").value = getCookie(p());
document.getElementById("Paige").onchange = "updateCookies();";
document.getElementById("paigedisp").innerHTML = p(1).toString();
updateCookies();
autoSave = setInterval(updateCookies, 20000);
//alert(navigator.userAgent);
if (getCookie("PC") == "1"){
document.getElementById("Share").style.display = "inline-block";
document.getElementById("Share 2").style.display = "inline-block";
document.getElementById("Receive").onclick = receiveDataJSON;
document.getElementById("Send").onclick = csendDataJSON;
document.getElementById("Send").style.width = "11%";
document.getElementById("Receive").style.width = "11%";
}
}
if (getCookie("PC") == "") {
if (confirm("Would you like to use this in Kindle view?")) {
setCookie("PC","0",36500);
}
else {
setCookie("PC","1",36500);
}
}
else {
setCookie("PC",getCookie("PC"),36500);
}