-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptHTMLEditor.js
More file actions
80 lines (60 loc) · 2.01 KB
/
scriptHTMLEditor.js
File metadata and controls
80 lines (60 loc) · 2.01 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
let bsp = "<h1>Beispielcode</h1>";
bsp += "Dieser Code ist ein typischer <b>HTML</b>-Code.<br>";
bsp += "Untersuche, wie die Zeilen umgebrochen und der Text <b>fett</b> gesetzt wird.";
let ausg = document.getElementById("HTML");
let eing = document.getElementById("Code");
document.getElementById("btn").onclick = function () {
codeToText();
}
document.getElementById("btn2").onclick = function () {
var txt = ausg.innerHTML;
console.log(txt);
eing.value = txt;
}
document.getElementById("btn3").onclick = function () {
eing.value = "";
ausg.innerHTML = "";
}
function codeToText() {
var txt = eing.value;
ausg.innerHTML = txt;
}
document.getElementById("btn4").onclick = function () {
eing.value = bsp;;
ausg.innerHTML = "";
}
window.onload = function () {
// Versucht im gleichen Verzeichnis die Datei code.txt zu laden
fetch('code.txt')
.then(response => {
if (!response.ok) {
throw new Error('Die Datei konnte nicht geladen werden.');
}
return response.text();
})
.then(data => {
document.getElementById('Code').value = data;
bsp = data;
})
.catch(error => {
// Keine Datei gefunden -> Code aus URL
const url = window.location.href;
console.log(url);
let pos = url.indexOf("code");
console.log(pos);
if (pos > 0) {
let txt = "";
for (var i = pos + 5; i < url.length; i++) {
txt = txt + url.charAt(i);
}
console.log(txt);
txt = txt.replaceAll("%3C", "<");
txt = txt.replaceAll("%3E", ">");
txt = txt.replaceAll("%20", " ");
txt = txt.replaceAll("%27", "'");
bsp = txt;
document.getElementById('Code').value = txt;
console.error('Es gab ein Problem mit dem Fetch-Vorgang:', error);
}
});
};