Dashboard Temp Share Shortlinks Frames API

HTMLify

index.html
Views: 46 | Author: devwajahat
  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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Comparison Note Builder</title>
    <style>
        :root {
            --bg-color: #f9fafb; --border-color: #e5e7eb; --primary: #4f46e5;
            --primary-hover: #4338ca; --danger: #ef4444; --text-main: #111827; --text-muted: #6b7280;
        }
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background-color: var(--bg-color); color: var(--text-main); margin: 0; padding: 2rem; display: flex; flex-direction: column; align-items: center; }
        .container { width: 100%; max-width: 1200px; background: white; border-radius: 8px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); padding: 2rem; }
        .toolbar { display: flex; gap: 0.5rem; padding: 0.75rem; background: #f3f4f6; border-radius: 6px; margin-bottom: 1.5rem; position: sticky; top: 0; z-index: 10; }
        .toolbar button { background: white; border: 1px solid var(--border-color); padding: 0.5rem 0.75rem; border-radius: 4px; cursor: pointer; font-weight: 500; transition: all 0.2s; }
        .toolbar button:hover { background: var(--border-color); }
        .comparison-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; table-layout: fixed; }
        .comparison-table th, .comparison-table td { border: 1px solid var(--border-color); padding: 1rem; vertical-align: top; position: relative; }
        .comparison-table th { background: #f8fafc; font-size: 1.25rem; }
        .sr-col { width: 50px; text-align: center; background: #f8fafc; font-weight: bold; color: var(--text-muted); }
        .action-col { width: 50px; text-align: center; background: #fff; }
        .del-btn { background: #fee2e2; color: var(--danger); border: none; border-radius: 4px; width: 24px; height: 24px; cursor: pointer; font-weight: bold; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; transition: 0.2s; }
        .del-btn:hover { background: var(--danger); color: white; }
        .del-col-btn { position: absolute; top: 4px; right: 4px; }
        .editor-cell { min-height: 100px; outline: none; }
        .editor-cell:focus { background-color: #fafafa; }
        .editor-cell h3 { margin-top: 0; font-size: 1.1rem; }
        .editor-cell p { margin-bottom: 0.5rem; }
        .actions { display: flex; gap: 1rem; margin-top: 1rem; }
        .btn { background: var(--primary); color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 6px; font-size: 1rem; cursor: pointer; font-weight: bold; }
        .btn:hover { background: var(--primary-hover); }
        .btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
        .btn-outline:hover { background: var(--primary); color: white; }
        
        /* Modal & Loading Styles */
        #embed-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); justify-content: center; align-items: center; z-index: 50; }
        .modal-content { background: white; padding: 2rem; border-radius: 8px; width: 80%; max-width: 800px; }
        .code-box { width: 100%; padding: 0.5rem; font-family: monospace; border: 1px solid var(--border-color); border-radius: 4px; background: #f9fafb; margin-bottom: 1rem; }
        textarea#embed-code { height: 100px; resize: vertical; }
        #loading { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.8); z-index: 100; justify-content: center; align-items: center; font-size: 1.5rem; font-weight: bold; color: var(--primary); flex-direction: column; gap: 1rem;}
    </style>
</head>
<body>

    <div id="loading">
        <div>Uploading directly to Cloudinary...</div>
        <div style="font-size: 1rem; color: #666;">Please wait, generating link.</div>
    </div>

    <div class="container">
        <h2>Comparison Note Builder</h2>
        
        <div class="toolbar" id="format-toolbar">
            <button onclick="formatText('bold')"><b>B</b></button>
            <button onclick="formatText('italic')"><i>I</i></button>
            <button onclick="formatText('underline')"><u>U</u></button>
            <button onclick="formatText('insertUnorderedList')">• List</button>
            <button onclick="formatText('formatBlock', 'H3')">Heading</button>
        </div>

        <table class="comparison-table" id="compare-table">
            <thead>
                <tr id="header-row">
                    <th class="sr-col">#</th>
                    <th class="editor-cell relative">
                        <div contenteditable="true" style="outline: none; min-height: 24px;">Topic 1</div>
                        <button class="del-btn del-col-btn" contenteditable="false" onclick="deleteColumn(this)"></button>
                    </th>
                    <th class="editor-cell relative">
                        <div contenteditable="true" style="outline: none; min-height: 24px;">Topic 2</div>
                        <button class="del-btn del-col-btn" contenteditable="false" onclick="deleteColumn(this)"></button>
                    </th>
                    <th class="action-col" id="action-header"></th>
                </tr>
            </thead>
            <tbody id="table-body">
                <tr>
                    <td class="sr-col">1</td>
                    <td class="editor-cell relative">
                        <div contenteditable="true" style="outline: none; min-height: 80px;"><h3>Point 1</h3><p>Description...</p></div>
                    </td>
                    <td class="editor-cell relative">
                        <div contenteditable="true" style="outline: none; min-height: 80px;"><h3>Point 1</h3><p>Description...</p></div>
                    </td>
                    <td class="action-col"><button class="del-btn" onclick="deleteRow(this)"></button></td>
                </tr>
            </tbody>
        </table>

        <div class="actions">
            <button class="btn btn-outline" onclick="addRow()">+ Add Row</button>
            <button class="btn btn-outline" onclick="addColumn()">+ Add Column</button>
            <button class="btn" onclick="saveToCloudinary()">Save & Generate Embed</button>
        </div>
    </div>

    <div id="embed-modal">
        <div class="modal-content">
            <h3 style="color: #10b981;">✔ Successfully Saved to Cloudinary!</h3>
            <p>Your comparison note has been saved. Use this code to embed it anywhere.</p>
            
            <label><strong>Iframe Embed Code:</strong></label>
            <textarea id="embed-code" class="code-box" readonly></textarea>
            
            <label><strong>Direct URL:</strong></label>
            <input type="text" id="embed-link" class="code-box" readonly>
            
            <div class="actions">
                <button class="btn btn-outline" onclick="closeModal()" style="border-color: #ef4444; color: #ef4444;">Close Window</button>
            </div>
        </div>
    </div>

 <script>
        const CLOUD_NAME = 'dqnbv7joh'; 
        const UPLOAD_PRESET = 'my_static_preset';

        function formatText(command, value = null) { 
            document.execCommand(command, false, value); 
            const activeEl = document.activeElement; 
            // Focus on the inner div if it's the header, or the td if it's the body
            if (activeEl && (activeEl.classList.contains('editor-cell') || activeEl.hasAttribute('contenteditable'))) {
                activeEl.focus(); 
            }
        }

        function updateSerialNumbers() { 
            // Use .rows instead of .children
            const rows = document.getElementById('table-body').rows; 
            for (let i = 0; i < rows.length; i++) { 
                // Use .cells[0] instead of querySelector
                rows[i].cells[0].innerText = i + 1; 
            } 
        }
        
        function addRow() {
            const tbody = document.getElementById('table-body');
            // FIX: Use .cells.length to strictly count table columns, ignoring extension tags
            const colCount = document.getElementById('header-row').cells.length; 
            const tr = document.createElement('tr');
            
            const tdSr = document.createElement('td'); 
            tdSr.className = 'sr-col'; 
            tr.appendChild(tdSr);
            
            for (let i = 0; i < colCount - 2; i++) {
                const td = document.createElement('td'); 
                td.className = 'editor-cell'; 
                td.setAttribute('contenteditable', 'true'); 
                td.innerHTML = '<p><br></p>'; 
                tr.appendChild(td);
            }
            
            const tdAction = document.createElement('td'); 
            tdAction.className = 'action-col'; 
            tdAction.innerHTML = `<button class="del-btn" onclick="deleteRow(this)">✖</button>`; 
            tr.appendChild(tdAction);
            
            tbody.appendChild(tr); 
            updateSerialNumbers();
        }

        function addColumn() {
            const headerRow = document.getElementById('header-row'); 
            const actionHeader = document.getElementById('action-header');
            
            const th = document.createElement('th'); 
            th.className = 'editor-cell relative'; 
            
            const textDiv = document.createElement('div');
            textDiv.setAttribute('contenteditable', 'true');
            textDiv.style.outline = 'none';
            textDiv.innerText = 'New Topic';
            
            const delBtn = document.createElement('button');
            delBtn.className = 'del-btn del-col-btn';
            delBtn.setAttribute('contenteditable', 'false');
            delBtn.innerText = '✖';
            delBtn.onclick = function() { deleteColumn(this); };

            th.appendChild(textDiv);
            th.appendChild(delBtn);
            
            headerRow.insertBefore(th, actionHeader);

            // FIX: Use .rows instead of .children
            const rows = document.getElementById('table-body').rows;
            for (let i = 0; i < rows.length; i++) {
                const td = document.createElement('td'); 
                td.className = 'editor-cell'; 
                td.setAttribute('contenteditable', 'true'); 
                td.innerHTML = '<p><br></p>';
                const actionCell = rows[i].querySelector('.action-col'); 
                rows[i].insertBefore(td, actionCell);
            }
        }

        function deleteRow(btn) { 
            btn.closest('tr').remove(); 
            updateSerialNumbers(); 
        }

        function deleteColumn(btn) {
            const th = btn.closest('th'); 
            // FIX: Use cellIndex to avoid counting extension tags
            const targetIndex = th.cellIndex; 
            
            th.parentNode.deleteCell(targetIndex);
            
            const rows = document.getElementById('table-body').rows; 
            for (let i = 0; i < rows.length; i++) { 
                rows[i].deleteCell(targetIndex); 
            }
        }

        async function saveToCloudinary() {
            document.getElementById('loading').style.display = 'flex';
            
            const tableClone = document.getElementById('compare-table').cloneNode(true);
            tableClone.querySelectorAll('.action-col').forEach(el => el.remove());
            tableClone.querySelectorAll('.del-btn').forEach(el => el.remove());
            
            // Clean up both TD and DIV contenteditables
            tableClone.querySelectorAll('[contenteditable]').forEach(cell => { 
                cell.removeAttribute('contenteditable'); 
                cell.classList.remove('editor-cell'); 
            });

            const finalHTMLContent = `
<div style="font-family: -apple-system, sans-serif; max-width: 100%; overflow-x: auto; padding: 1rem;">
    <style>
        .embedded-table { width: 100%; border-collapse: collapse; }
        .embedded-table th, .embedded-table td { border: 1px solid #e5e7eb; padding: 1rem; vertical-align: top; }
        .embedded-table th { background: #f8fafc; font-size: 1.1rem; text-align: left; }
        .embedded-table .sr { width: 40px; text-align: center; background: #f8fafc; font-weight: bold; color: #6b7280; }
        .embedded-table h3 { margin-top: 0; font-size: 1rem; color: #111827; }
        .embedded-table p { margin-bottom: 0; color: #374151; }
    </style>
    ${tableClone.outerHTML.replace('class="comparison-table"', 'class="embedded-table"').replace(/sr-col/g, 'sr')}
</div>`;

            const randomStr = Math.random().toString(36).substring(2, 8);
            const filename = `comparison_embed_${randomStr}.html`;
            const blob = new Blob([finalHTMLContent.trim()], { type: 'text/html' });

            const formData = new FormData();
            formData.append('file', blob, filename);
            formData.append('upload_preset', UPLOAD_PRESET);
            formData.append('resource_type', 'raw'); 

            try {
                const response = await fetch(`https://api.cloudinary.com/v1_1/${CLOUD_NAME}/auto/upload`, {
                    method: 'POST',
                    body: formData
                });

                const data = await response.json();
                
                if (response.ok) {
                    document.getElementById('loading').style.display = 'none';
                    
                    const fileUrl = data.secure_url;
                    document.getElementById('embed-link').value = fileUrl;
                    document.getElementById('embed-code').value = `<iframe src="${fileUrl}" width="100%" height="500px" style="border:1px solid #e5e7eb; border-radius: 8px;"></iframe>`;
                    
                    document.getElementById('embed-modal').style.display = 'flex';
                } else {
                    document.getElementById('loading').style.display = 'none';
                    alert("Cloudinary Error: " + data.error.message);
                }
            } catch (error) {
                document.getElementById('loading').style.display = 'none';
                alert("Network error. Could not connect to Cloudinary.");
                console.error(error);
            }
        }

        function closeModal() { document.getElementById('embed-modal').style.display = 'none'; }
    </script>
</body>
</html>