1 2 3let chatMore = { 4 devConsoleOpen: false, 5 toggleEruda() { 6 const previewFrame = document.getElementById('html-preview'); 7 let eruda = previewFrame.contentWindow.eruda; 8 9 if (!eruda) { 10 const script = previewFrame.contentWindow.document.createElement('script'); 11 script.src = 'https://cdn.jsdelivr.net/npm/eruda'; 12 script.onload = () => { 13 eruda = previewFrame.contentWindow.eruda; 14 eruda.init(); 15 eruda.show(); 16 this.devConsoleOpen = true; 17 }; 18 previewFrame.contentWindow.document.body.appendChild(script); 19 } else { 20 if (this.devConsoleOpen) { 21 eruda.hide(); 22 this.devConsoleOpen = false; 23 } else { 24 eruda.show(); 25 this.devConsoleOpen = true; 26 } 27 } 28 }, 29 editor: null, 30 /** @type {EditorFile[]} */ 31 editorFiles: [new EditorFile({ name: 'index.html', content: '', hidden: false })], 32 33 async OnEditorLoaded() { 34 35 let options = { 36 value: '', 37 language: 'html', 38 theme: 'vs-dark', 39 automaticLayout: this.isMobile, 40 minimap: { enabled: false }, 41 readOnly: this.isMobile, 42 domReadOnly: this.isMobile 43 }; 44 45 this.editor = monaco.editor.create(document.getElementById('monaco-editor'), options); 46 this.editor.onDidChangeModelContent(() => { 47 const updatedContent = this.editor.getValue(); 48 const activeEditorTab = this.editorFiles[this.activeEditorTab]; 49 50 if (activeEditorTab) { 51 activeEditorTab.content = updatedContent; 52 } 53 54 const fileData = this.editorFiles 55 .filter(file => !file.isBinary) 56 .map(file => { 57 const isHtml = file.name.endsWith('.html'); 58 const type = isHtml ? 'text/html' : file.name.endsWith('.js') ? 'application/javascript' : 'text/plain'; 59 const CONTENT = !isHtml ? file.content : `<!DOCTYPE html> 60 61 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css"> 62 <script src="https://cdn.jsdelivr.net/npm/toastify-js"></script> 63 <script src="../../huggingFace.js"></script> 64 <script src="../../errorsForward.js"></script> 65 <script src="../../libs/output.js"></script> 66 ` + file.content; 67 return { 68 name: file.name, 69 type, 70 buffer: new TextEncoder().encode(CONTENT).buffer 71 }; 72 }); 73 this.UploadFiles(fileData); 74 75 let html = activeEditorTab?.name?.toLowerCase()?.endsWith('.html') ? activeEditorTab : this.editorFiles.find(a => a.name.toLowerCase().endsWith('.html') && a.hidden == false); 76 if (html) 77 { 78 this.updatePreview(html); 79 } 80 }); 81 82 this.editor.addAction({ 83 id: 'toggle-edit', 84 label: 'Toggle Edit', 85 contextMenuGroupId: 'navigation', 86 contextMenuOrder: 1, 87 run: () => { 88 options.readOnly = options.domReadOnly = !options.readOnly; 89 this.editor.updateOptions(options); 90 } 91 }); 92 93 this.editor.addAction({ 94 id: 'copy-file', 95 label: 'Copy File', 96 contextMenuGroupId: 'navigation', 97 contextMenuOrder: 1, 98 run: () => { 99 this.copyFile(this.editorFiles[this.activeEditorTab].content); 100 } 101 }); 102 103 await this.loadChat(this.params.chatId); 104 }, 105 async generateSuggestions(message) { 106 const prompt = `Generate 5 coding task suggestions based on the following message: \n"""\n${message}\n"""\nEach suggestion should be brief and concise. Return the suggestions as a JSON array. 107 108 Example: 109 Input: "I want to create a personal blog." 110 Output: [ 111 {"name": "Create a homepage", "content": "Design a homepage for the blog."}, 112 {"name": "Implement a comment section", "content": "Add a feature for users to comment on posts."}, 113 {"name": "Set up a contact form", "content": "Create a contact form for user inquiries."}, 114 {"name": "Add social media links", "content": "Include links to social media profiles."}, 115 {"name": "Optimize for SEO", "content": "Implement SEO best practices for better visibility."} 116 ]`; 117 118 try { 119 let response = ''; 120 for await (const chunk of getChatGPTResponse({ 121 messages: [{ role: "user", content: prompt }], 122 model: "liquid/lfm-40b:free", 123 max_tokens: 1200, 124 temperature: 0.5 + Math.random() * 0.2, 125 })) { 126 response += chunk.delta.content; 127 } 128 129 const suggestionsJson = response.match(/(\[.*?\])/s)[0]; 130 this.contact.suggestions = JSON.parse(suggestionsJson); 131 } catch (error) { 132 console.error('Error generating suggestions:', error); 133 } 134 }, 135} 136 137 138 139 140window.addEventListener('dragover', (event) => event.preventDefault()); 141window.addEventListener('drop', async (event) => { 142 event.preventDefault(); 143 const files = event.dataTransfer.files; 144 145 if (files.length) { 146 const fileContents = await Promise.all(Array.from(files).map(async (file) => { 147 if (file.type === 'application/pdf') { 148 const reader = new FileReader(); 149 reader.onload = function () { 150 const typedarray = new Uint8Array(reader.result); 151 pdfjsLib.getDocument(typedarray).promise.then(function (pdf) { 152 let totalPages = pdf.numPages; 153 let text = ''; 154 let currentPage = 1; 155 156 const extractText = function (pageNum) { 157 pdf.getPage(pageNum).then(function (page) { 158 page.getTextContent().then(function (textContent) {
159 textContent.items.forEach(function (item) { 160 text += item.str + '\n'; 161 }); 162 if (currentPage < totalPages) { 163 currentPage++; 164 extractText(currentPage); 165 } else { 166 console.log(text); 167 chat.editorFiles.push({ name: file.name, content: text, isBinary: false,hidden:false }); 168 } 169 }); 170 }); 171 }; 172 173 extractText(currentPage); 174 }); 175 }; 176 reader.readAsArrayBuffer(file); 177 } else { 178 const buffer = await file.arrayBuffer(); 179 const content = new TextDecoder().decode(buffer); 180 const isTextFile = file.type.startsWith('text/'); 181 const existingFile = chat.editorFiles.find(a => a.name === file.name); 182 const fileContent = isTextFile ? content : await extractMeaningfulText(file); 183 184 if (existingFile) { 185 existingFile.content = fileContent; 186 } else { 187 chat.editorFiles.push({ name: file.name, content: fileContent, isBinary: !isTextFile,hidden:false }); 188 } 189 } 190 })); 191 192 chat.updateEditorContent(); 193 navigator.serviceWorker.controller.postMessage({ 194 action: 'uploadFiles', 195 files: fileContents 196 }); 197 } 198}); 199 200 201 202 203window.addEventListener('message', function (event) { 204 if (event.data.error && !event.data.lastError) { 205 chat.newMessage = event.data.message; 206 chat.setActiveTab('chat'); 207 } 208 if (event.data.error === true && event.data.message!= "Script error.") { 209 let message = event.data.message; 210 //chat.newMessage = message; 211 212 if(chat.aborted && !event.data.lastError && !message.includes("Log:")) 213 { 214 if (globalThis.iframeModal) 215 M.Modal.getInstance(iframeModal).close(); 216 chat.setActiveTab("chat"); 217 chat.sendMessage(); 218 } 219 } 220}); 221 222 223function UploadChat() { 224 fetch( siteUrl + '/saveChat', { 225 method: 'POST', 226 headers: { 227 'Content-Type': 'application/json', 228 }, 229 body: JSON.stringify({ 230 version: 3, 231 chatId: chat.params.chatId, 232 messages: chat.messages, 233 title: chat.getChatTitle(), 234 editorFiles: chat.editorFiles, 235 donthash:true 236 }), 237 }).then(response => response.json()).then(data => console.log('Messages sent successfully:', data)).catch((error) => { 238 console.error('Error sending messages:', error); 239 }); 240} 241 242let deferredPrompt=null; 243window.addEventListener('beforeinstallprompt', (e) => { 244 console.log("123") 245 e.preventDefault(); 246 deferredPrompt = e; 247 promptInstall(); 248}); 249 250async function promptInstall() { 251 252 deferredPrompt.prompt(); 253 const { outcome } = await deferredPrompt.userChoice; 254 if (outcome === 'accepted') { 255 console.log('User accepted the A2HS prompt'); 256 //window.close(); 257 window.location.href = 'preview/' + chat.params.chatId + '/index.html'; 258 } 259 deferredPrompt = null; 260 261}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.