ThorAILabs commited on
Commit
a22420b
·
verified ·
1 Parent(s): f179228

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +76 -76
index.html CHANGED
@@ -2,82 +2,70 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>Simple Docs Clone</title>
6
- <!-- Required libraries -->
 
 
 
 
 
 
 
 
7
  <script src="https://unpkg.com/mammoth@1.4.8/mammoth.browser.min.js"></script>
8
- <script src="https://cdn.jsdelivr.net/npm/html-docx-js@0.3.1/dist/html-docx.js"></script>
9
- <style>
10
- #editor {
11
- width: 80%;
12
- height: 80vh;
13
- margin: 20px auto;
14
- padding: 20px;
15
- border: 1px solid #ccc;
16
- overflow-y: auto;
17
- }
18
- .toolbar {
19
- display: flex;
20
- gap: 10px;
21
- padding: 10px;
22
- background: #f8f9fa;
23
- border-bottom: 1px solid #ddd;
24
- }
25
- button {
26
- padding: 5px 10px;
27
- cursor: pointer;
28
- }
29
- </style>
30
  </head>
31
- <body>
32
- <div class="toolbar">
33
- <button onclick="formatText('bold')"><strong>B</strong></button>
34
- <button onclick="formatText('italic')"><em>I</em></button>
35
- <button onclick="formatText('underline')"><u>U</u></button>
36
- <input type="file" id="importFile" accept=".docx" />
37
- <button onclick="exportDOCX()">Export DOCX</button>
38
- <button onclick="toggleAlignment()">Align</button>
39
- <label><input type="checkbox" id="autosave"> Autosave</label>
40
- </div>
41
- <div id="editor" contenteditable="true"></div>
42
-
43
- <script>
44
- // Initialize editor with saved content
45
- document.addEventListener('DOMContentLoaded', () => {
46
- const savedContent = getCookie('documentContent');
47
- if(savedContent) {
48
- document.getElementById('editor').innerHTML =
49
- decodeURIComponent(savedContent);
50
- }
51
 
52
- // Autosave every 5 seconds
53
- setInterval(() => {
54
- if(document.getElementById('autosave').checked) {
55
- saveDocument();
56
- }
57
- }, 5000);
58
- });
 
 
 
 
59
 
60
- // Text formatting
61
- function formatText(command) {
62
- document.execCommand(command, false, null);
63
- }
 
 
64
 
65
- // Alignment toggle
66
- let alignState = 0;
67
- function toggleAlignment() {
68
- const alignments = ['left', 'center', 'right', 'justify'];
69
- document.execCommand('justify' + alignments[alignState]);
70
- alignState = (alignState + 1) % 4;
71
- }
72
 
73
- // Cookie handling
74
- function saveDocument() {
75
- const content = document.getElementById('editor').innerHTML;
76
- document.cookie = `documentContent=${encodeURIComponent(content)}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
77
- }
78
 
79
- function getCookie(name) {
80
- return document.cookie.split('; ').find(row => row.startsWith(name))?.split('=')[1];
 
 
 
 
 
81
  }
82
 
83
  // DOCX Import
@@ -85,11 +73,9 @@
85
  const file = e.target.files[0];
86
  const reader = new FileReader();
87
 
88
- reader.onload = function(event) {
89
- mammoth.convertToHtml({ arrayBuffer: event.target.result })
90
- .then(result => {
91
- document.getElementById('editor').innerHTML = result.value;
92
- })
93
  .catch(err => console.error(err));
94
  };
95
 
@@ -98,15 +84,29 @@
98
 
99
  // DOCX Export
100
  function exportDOCX() {
101
- const content = document.getElementById('editor').innerHTML;
 
 
 
 
 
 
102
  const converted = htmlDocx.asBlob(content);
103
- const url = window.URL.createObjectURL(converted);
104
 
105
  const a = document.createElement('a');
106
  a.href = url;
107
  a.download = 'document.docx';
108
  a.click();
 
109
  }
 
 
 
 
 
 
 
110
  </script>
111
  </body>
112
  </html>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>DocX Editor</title>
7
+
8
+ <!-- Tailwind CSS -->
9
+ <script src="https://cdn.tailwindcss.com"></script>
10
+
11
+ <!-- Font Awesome -->
12
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
13
+
14
+ <!-- DOCX Libraries -->
15
  <script src="https://unpkg.com/mammoth@1.4.8/mammoth.browser.min.js"></script>
16
+ <script src="https://cdn.jsdelivr.net/npm/html-docx-js@1.1.1/dist/html-docx.min.js"></script>
17
+
18
+ <!-- Cookie Library -->
19
+ <script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  </head>
21
+ <body class="bg-gray-100">
22
+ <div class="container mx-auto px-4">
23
+ <!-- Toolbar -->
24
+ <div class="bg-white shadow-md sticky top-0 p-4 mb-4 flex gap-4">
25
+ <input type="file" id="importFile" class="hidden" accept=".docx">
26
+ <button onclick="document.getElementById('importFile').click()"
27
+ class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded flex items-center gap-2">
28
+ <i class="fas fa-file-import"></i>
29
+ Import DOCX
30
+ </button>
 
 
 
 
 
 
 
 
 
 
31
 
32
+ <button onclick="exportDOCX()"
33
+ class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded flex items-center gap-2">
34
+ <i class="fas fa-file-export"></i>
35
+ Export DOCX
36
+ </button>
37
+
38
+ <div class="flex items-center ml-auto text-gray-500">
39
+ <i class="fas fa-save mr-2"></i>
40
+ <span id="saveStatus">Auto-saved</span>
41
+ </div>
42
+ </div>
43
 
44
+ <!-- Editor -->
45
+ <div id="editor"
46
+ class="bg-white shadow-lg min-h-[calc(100vh-150px)] p-8 text-lg focus:outline-none"
47
+ contenteditable="true"
48
+ oninput="scheduleSave()"></div>
49
+ </div>
50
 
51
+ <script>
52
+ let timeoutId;
53
+ const COOKIE_NAME = 'documentContent';
54
+ const EDITOR = document.getElementById('editor');
 
 
 
55
 
56
+ // Load saved content
57
+ window.onload = () => {
58
+ const savedContent = Cookies.get(COOKIE_NAME);
59
+ if(savedContent) EDITOR.innerHTML = savedContent;
60
+ };
61
 
62
+ // Auto-save functionality
63
+ function scheduleSave() {
64
+ clearTimeout(timeoutId);
65
+ timeoutId = setTimeout(() => {
66
+ Cookies.set(COOKIE_NAME, EDITOR.innerHTML, { expires: 7 });
67
+ document.getElementById('saveStatus').textContent = 'Auto-saved just now';
68
+ }, 2000);
69
  }
70
 
71
  // DOCX Import
 
73
  const file = e.target.files[0];
74
  const reader = new FileReader();
75
 
76
+ reader.onload = function() {
77
+ mammoth.convertToHtml({ arrayBuffer: reader.result })
78
+ .then(result => EDITOR.innerHTML = result.value)
 
 
79
  .catch(err => console.error(err));
80
  };
81
 
 
84
 
85
  // DOCX Export
86
  function exportDOCX() {
87
+ const content = `
88
+ <html>
89
+ <head><meta charset="UTF-8"></head>
90
+ <body>${EDITOR.innerHTML}</body>
91
+ </html>
92
+ `;
93
+
94
  const converted = htmlDocx.asBlob(content);
95
+ const url = URL.createObjectURL(converted);
96
 
97
  const a = document.createElement('a');
98
  a.href = url;
99
  a.download = 'document.docx';
100
  a.click();
101
+ URL.revokeObjectURL(url);
102
  }
103
+
104
+ // Handle paste to remove formatting
105
+ EDITOR.addEventListener('paste', e => {
106
+ e.preventDefault();
107
+ const text = (e.clipboardData || window.clipboardData).getData('text');
108
+ document.execCommand('insertText', false, text);
109
+ });
110
  </script>
111
  </body>
112
  </html>