diff --git a/apps/App Maker/script.js b/apps/App Maker/script.js
index 5515e13..a01f204 100644
--- a/apps/App Maker/script.js
+++ b/apps/App Maker/script.js
@@ -1,5 +1,7 @@
let htmlCode = '', cssCode = '', jsCode = '';
+let mediaDictionary = {};
+
function detectAndProcessCode(clipboardText) {
if (clipboardText.includes("```")) {
// Split text by lines
@@ -29,8 +31,8 @@ function detectAndProcessCode(clipboardText) {
}
} else {
// Fallback to original detection method for text without triple back quotes
- const codeType = detectCodeType(clipboardText);
- processCodeBlock(codeType, clipboardText);
+ const { type: codeType, text: modifiedText } = detectCodeType(clipboardText);
+ processCodeBlock(codeType, modifiedText);
}
}
@@ -65,7 +67,7 @@ function handlePasteContent(clipboardContent) {
// If an error occurs, copy error information to the clipboard
copyTextToClipboard(`Error while pasting: ${err}\n\nPasted Content:\n${clipboardContent}`);
// Display user-friendly error message
- alert("An error while pasting occurred and has been placed on the clipboard. Please go to your chatbot and paste the error so it can fix it. If you don't know how to paste then ask it.");
+ displayMessage("An error while pasting occurred and has been placed on the clipboard. Please go to your chatbot and paste the error so it can fix it. If you don't know how to paste then ask it.", true);
}
}
@@ -151,27 +153,42 @@ document.getElementById('runBtn').addEventListener('click', function() {
});
function detectCodeType(text) {
- // Trim leading whitespace and check the first character
- const firstChar = text.trim().charAt(0);
+ // Trim leading and trailing whitespace
+ let cleanedText = text.trim();
+
+ // Remove HTML comments
+ cleanedText = cleanedText.replace(//g, '').trim();
+
+ // Check for CSS wrapped in ')) {
+ cleanedText = cleanedText.slice(''.length).trim();
+ return { type: 'css', text: cleanedText };
+ }
+
+ // Check for JavaScript wrapped in ')) {
+ cleanedText = cleanedText.slice(''.length).trim();
+ return { type: 'javascript', text: cleanedText };
+ }
// Check for HTML
- if (firstChar === '<') {
- return 'html';
+ if (cleanedText.charAt(0) === '<') {
+ return { type: 'html', text: cleanedText };
}
- // Check for CSS
+ // Check for CSS pattern
const cssPattern = /[#.][a-zA-Z0-9_-]+\s*\{[\s\S]+?\}/gm;
- if (cssPattern.test(text)) {
- return 'css';
+ if (cssPattern.test(cleanedText)) {
+ return { type: 'css', text: cleanedText };
}
// Check for JavaScript syntax errors
- if (hasSyntaxError(text)) {
- return 'bad_javascript';
+ if (hasSyntaxError(cleanedText)) {
+ return { type: 'bad_javascript', text: cleanedText };
}
// Default to JavaScript
- return 'javascript';
+ return { type: 'javascript', text: cleanedText };
}
function hasSyntaxError(code) {
@@ -208,35 +225,83 @@ function updateDownloadButtonState() {
}
function updateHTML(newHTML) {
- // Extract and keep CSS
- const cssRegex = /([\s\S]*?)<\/style>/gi;
- let extractedCSS = '';
- newHTML = newHTML.replace(cssRegex, function(match, css) {
- extractedCSS += css.trim() + '\n';
- return '';
- });
- mergeCSS(extractedCSS);
-
- // Extract and keep JavaScript without src attribute
- const jsRegex = /