-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·52 lines (37 loc) · 1.46 KB
/
script.js
File metadata and controls
executable file
·52 lines (37 loc) · 1.46 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
/*! Minimalist Web Notepad | https://github.com/pereorga/minimalist-web-notepad */
function uploadContent() {
if (content !== textarea.value) {
// Text area value has changed.
var temp = textarea.value;
var request = new XMLHttpRequest();
request.open('POST', window.location.href, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onload = function() {
if (request.readyState === 4) {
// Request has ended, check again after 1 second.
content = temp;
setTimeout(uploadContent, 1000);
}
}
request.onerror = function() {
// On connection error, try again after 1 second.
setTimeout(uploadContent, 1000);
}
// Send the request.
request.send('t=' + encodeURIComponent(temp));
// Make the content available to print.
printable.removeChild(printable.firstChild);
printable.appendChild(document.createTextNode(temp));
}
else {
// Content has not changed, check again after 1 second.
setTimeout(uploadContent, 1000);
}
}
var textarea = document.getElementById('content');
var printable = document.getElementById('printable');
var content = textarea.value;
// Make the content available to print.
printable.appendChild(document.createTextNode(content));
textarea.focus();
uploadContent();