-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
108 lines (95 loc) · 2.98 KB
/
index.php
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
<?php
$file = 'note.txt';
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if (isset($_POST['text']) && !empty($_POST['text']))
{
$data = $_POST['text'];
file_put_contents($file, nl2br($data)) ;
}
}
else
{
$data = '';
if (file_exists($file))
{
$data = file_get_contents($file);
}
?>
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8"/>
<meta name="author" content="Riccardo Mollo"/>
<meta name="copyright"content="Riccardo Mollo"/>
<meta name="reply-to" content="[email protected]"/>
<meta name="description" content="SimpleNotePad"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta http-equiv="default-style" content="css/style.css"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="pragma" content="no-cache"/>
<link rel="icon" type="image/png" href="img/favicon-16x16.png" sizes="16x16"/>
<link rel="icon" type="image/png" href="img/favicon-32x32.png" sizes="32x32"/>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Inconsolata" crossorigin="anonymous"/>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/>
<title>SimpleNotePad</title>
<script>
window.onload = function prepare()
{
note = document.getElementById('note');
if (note.innerText && note.innerText !== "")
{
text_b64dec = atob(note.innerText);
note.innerText = text_b64dec;
}
if (window.addEventListener)
{
note.addEventListener('DOMSubtreeModified', contentChanged, false);
}
else if (window.attachEvent)
{
note.attachEvent('DOMSubtreeModified', contentChanged);
}
function contentChanged()
{
save_data(btoa(note.innerText));
}
};
function save_data(data)
{
data = 'text=' + data;
xhr = new XMLHttpRequest();
xhr.open('POST', 'index.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function()
{
if (xhr.status !== 200 && xhr.status !== 0)
{
// alert('Error! Server responded with HTTP code ' + xhr.status + '.');
note = document.getElementById('note');
note.style.backgroundColor = '#ff2800';
// if error occurs, notepad blinks red for half a second
setTimeout(function()
{
note.style.backgroundColor = '#dedede';
}, 500);
return;
}
};
xhr.send(data);
}
function reset()
{
document.getElementById('note').innerText = '';
}
</script>
</head>
<body>
<div id="note" contenteditable="true"><?php echo $data; ?></div>
<button id="reset" class="pure-material-button-contained" onclick="reset();">Reset</button>
</body>
</html>
<?php
}
?>