-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 2.82 KB
/
script.js
File metadata and controls
74 lines (62 loc) · 2.82 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
(function(){
// Helper to run document.execCommand
window.exec = function(cmd, val){
document.execCommand(cmd, false, val || null);
document.getElementById('editor').focus();
}
window.execColor = function(cmd, val){
// hiliteColor may be "backColor" in some browsers
try{ document.execCommand(cmd, false, val); }catch(e){ document.execCommand('backColor', false, val); }
document.getElementById('editor').focus();
}
window.execFont = function(font){
if(!font) return; document.execCommand('fontName', false, font); document.getElementById('editor').focus();
}
window.insertImage = function(event){
const file = event.target.files[0]; if(!file) return;
const reader = new FileReader();
reader.onload = function(e){ document.execCommand('insertImage', false, e.target.result); }
reader.readAsDataURL(file);
}
window.createLink = function(){
const url = prompt('Enter URL (include https://)'); if(!url) return; document.execCommand('createLink', false, url);
}
window.saveContent = function(){
const html = document.getElementById('editor').innerHTML;
localStorage.setItem('rte-content', html);
showToast('Saved to localStorage');
}
window.loadContent = function(){
const html = localStorage.getItem('rte-content');
if(html){ document.getElementById('editor').innerHTML = html; showToast('Loaded from localStorage'); }
else showToast('No saved content found');
}
window.clearEditor = function(){ if(confirm('Clear editor?')) { document.getElementById('editor').innerHTML = ''; } }
window.downloadHtml = function(){
const content = document.getElementById('editor').innerHTML;
const blob = new Blob([content], {type:'text/html'});
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'content.html'; a.click();
}
window.toggleFullscreen = function(){
const el = document.getElementById('editor');
if(!document.fullscreenElement){
if(el.requestFullscreen) el.requestFullscreen();
el.classList.add('fullscreen');
} else {
if(document.exitFullscreen) document.exitFullscreen();
el.classList.remove('fullscreen');
}
}
window.showToast = function(message){
// very small ephemeral feedback
const t = document.createElement('div');
t.textContent = message; t.style.position='fixed'; t.style.right='12px'; t.style.bottom='12px';
t.style.background='rgba(0,0,0,0.75)'; t.style.color='#fff'; t.style.padding='8px 12px'; t.style.borderRadius='6px';
t.style.zIndex = 99999; document.body.appendChild(t);
setTimeout(()=> t.remove(), 1600);
}
// load automatically if saved
document.addEventListener('DOMContentLoaded', function(){
const saved = localStorage.getItem('rte-content'); if(saved) document.getElementById('editor').innerHTML = saved;
});
})();