-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
150 lines (137 loc) · 6.5 KB
/
editor.html
File metadata and controls
150 lines (137 loc) · 6.5 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
<title>Web Editor</title>
<!--Bootstrap v5 icon link-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
<!--Browse Bootstrap v5 icon here: https://icons.getbootstrap.com-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="/css/editor.css" rel="stylesheet">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="/css/forms.css">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1889527741439078"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container mt-3">
<div class="modal fade" id="editorModal">
<div class="modal-dialog modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Editor</h4>
<button type="button" class="close" data-dismiss="modal">x</button>
</div>
<div class="modal-body">
<textarea class="form-control" style="height: 70%;" id="filebox" spellcheck="false" autocapitalize="off" autocomplete="off"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="save">Save</button>
<button type="button" class="btn btn-danger" onclick="window.location = window.location">Close</button>
</div>
</div>
</div>
</div>
</div>
<div class="page_content">
<br>
<h3 style="font-family: 'calibri';">File Editor</h3>
<hr>
<form>
<div class="mb-3">
<div class="alert alert-info alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
Your are using english. <a href="https://accessretrieved.github.io/editor_zh-cn.html">Switch to Chinese</a>
</div>
<label class="form-label" for="file">Upload file</label>
<br>
<label class="file">
<input type="file" id="file" aria-label="File browser" onchange="changeName();">
<span class="file-custom" id="filename" style="text-align: left;">Choose a File</span>
</label>
<br><br><br>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#editorModal">Start</button>
</div>
</form>
</div>
</body>
<script>
var input = document.getElementById("file");
var file = "";
var ex = "";
var imgs = ['png', 'jpg', 'svg', 'heic', 'HEIC',
'gif', 'GIF', 'PSD', 'XCF', 'psd',
'xcf', 'ai', 'AI', 'cdr', 'CDR',
'tiff', 'TIFF', 'tif', 'TIF', 'bmp',
'BMP', 'eps', 'EPS', 'raw', 'RAW',
'cr2', 'CR2', 'nef', 'NEF', 'orf',
'ORF', 'sr2', 'SR2'];
var vids = ['mp4', 'm4a', 'MP4', 'M4A', 'webm',
'WEBM', 'mkv', 'MKV', 'flv', 'FLV',
'VOB', 'vob', 'ogv', 'OGV', 'ogg',
'OGG', 'drc', 'DRC', 'gifv', 'GIFV',
'mng', 'MNG', 'avi', 'AVI', 'mov',
'MOV', 'mpg', 'MPG', 'mpeg', 'MPEG'];
var audios = ['mp3', 'm4p', 'MP3', 'M4P', 'aiff',
'AIFF', 'alac', 'ALAC', 'wma', 'WMA']
function getFile(filePath) {
return filePath.substr(filePath.lastIndexOf('\\') + 1).split('.')[0];
}
function getoutput() {
file = getFile(input.value);
ex = input.value.split('.')[1];
}
function changeName() {
getoutput();
if (imgs.includes(ex) == true || vids.includes(ex) == true || audios.includes(ex) == true) {
alert('Sorry, not a supported format.');
input.value = '';
document.getElementById('filename').innerHTML = "Choose a File";
} else {
document.getElementById('filename').innerHTML = file + "." + ex;
}
}
function saveTextAsFile() {
getoutput();
var textToWrite = document.getElementById('filebox').value;
var textFileAsBlob = new Blob([ textToWrite ], { type: 'text/plain' });
var fileNameToSaveAs = file + "." + ex;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
var button = document.getElementById('save');
button.addEventListener('click', saveTextAsFile);
function destroyClickedElement(event) {
document.body.removeChild(event.target);
}
function readSingleFile(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
displayContents(contents);
};
reader.readAsText(file);
}
function displayContents(contents) {
var element = document.getElementById('filebox');
element.textContent = contents;
}
document.getElementById('file')
.addEventListener('change', readSingleFile, false);
</script>
</html>