-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (62 loc) · 2.24 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>OldText</title>
<style>
body { font-family: sans-serif; margin: 10px; }
textarea { width: 100%; height: 300px; }
button { margin: 5px; }
</style>
</head>
<body>
<textarea id="editor" rows="20" cols="80"></textarea><br>
<button onclick="saveText()">Save</button>
<button onclick="loadText()">Load</button>
<button onclick="clearText()">Clear</button>
<button onclick="boldText()">Bold</button>
<button onclick="italicText()">Italic</button>
<button onclick="countWords()">Word Count</button>
<script>
function saveText() {
var text = document.getElementById('editor').value;
document.cookie = "savedText=" + escape(text);
alert('Text saved!');
}
function loadText() {
var cookies = document.cookie.split(';');
for(var i=0; i < cookies.length; i++) {
var c = cookies[i].trim();
if (c.indexOf("savedText=") == 0) {
document.getElementById('editor').value = unescape(c.substring(10, c.length));
return;
}
}
alert('No saved text found.');
}
function clearText() {
document.getElementById('editor').value = '';
}
function boldText() {
var textarea = document.getElementById('editor');
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var sel = textarea.value.substring(start, end);
var replacement = '*' + sel + '*';
textarea.value = textarea.value.substring(0, start) + replacement + textarea.value.substring(end);
}
function italicText() {
var textarea = document.getElementById('editor');
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var sel = textarea.value.substring(start, end);
var replacement = '_' + sel + '_';
textarea.value = textarea.value.substring(0, start) + replacement + textarea.value.substring(end);
}
function countWords() {
var text = document.getElementById('editor').value;
var wordCount = text.split(/\s+/).filter(function(n) { return n != '' }).length;
alert('Word count: ' + wordCount);
}
</script>
</body>
</html>