-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainview.html
executable file
·86 lines (74 loc) · 2.93 KB
/
mainview.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<title>Welcome to c64Writer.</title>
<meta name="description" content="c64Writer is a lightweight cross-platform simple text editor designed to look like the original Commodore 64 boot screen.>
<meta name="author" content="Nick Louridas">
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<div class="border2">
<div class="popup">
<span class="popuptext" id="savePopup">File saved in Downloads folder.</span>
<span class="popuptext" id="copyPopup">Selection copied to Clipboard.</span>
<span class="popuptext" id="pastePopup">Clipboard pasted to document.</span>
</div>
<div class="container1">
<div class="titlebar">**** COMMODORE 64 WRITER V1.2 ****</div>
<div class="spacer">64K RAM SYSTEM 38911 BASIC BYTES FREE</div>
</div>
<div class="container2"> READY.<p></p>
<textarea id="maintxt" class="contents" autofocus></textarea>
</div>
<div class="container3">Save: <input id="inputFileNameToSaveAs" value="default.txt" class="form1"></input> <button onclick="saveTextAsFile()">[ OK ]</button> * Load: <input type="file" id="fileToLoad"/><button onclick="loadFileAsText()" class="load-button">[ OK ]</button>
</div>
</div>
<script type="text/javascript">
document.onkeyup = function(e)
{
if (e.ctrlKey && e.which == 67) {
var popup = document.getElementById("copyPopup");
popup.classList.toggle("show");
setTimeout(() => popup.classList.toggle("show"), 2000);
}
else if (e.ctrlKey && e.which == 86) {
var popup = document.getElementById("pastePopup");
popup.classList.toggle("show");
setTimeout(() => popup.classList.toggle("show"), 2000);
}
}
function saveTextAsFile()
{
var textToSave = document.getElementById("maintxt").value;
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
var popup = document.getElementById("savePopup");
popup.classList.toggle("show");
setTimeout(() => popup.classList.toggle("show"), 2000);
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
function loadFileAsText()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.getElementById("maintxt").value = textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
}
</script>
</body>
</html>