-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappend-prepend.html
38 lines (37 loc) · 1.24 KB
/
append-prepend.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Tools - Append/prepend</title>
<script src="components/sidebar-component.js"></script>
<script src="components/header-component.js"></script>
<link href="index.css" rel="stylesheet">
</head>
<body>
<header-component></header-component>
<sidebar-component></sidebar-component>
<main>
<select id="operation-choice" title="Operation choice">
<option value="append">Append</option>
<option value="prepend">Prepend</option>
</select>
<textarea id="input"></textarea>
<input id="text-to-add" type="text"/>
<button onclick="convert()">Convert</button>
<code id="output"></code>
</main>
<script>
function convert() {
const operation = document.getElementById('operation-choice').value;
const input = document.getElementById('input').value;
const lines = input.split('\n');
const textToAdd = document.getElementById('text-to-add').value;
if (operation === 'append') {
document.getElementById('output').innerHTML = lines.map(line => line + textToAdd).join('<br/>');
} else {
document.getElementById('output').innerHTML = lines.map(line => textToAdd + line).join('<br/>');
}
}
</script>
</body>
</html>