-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML.html
More file actions
173 lines (166 loc) · 5.8 KB
/
Copy pathHTML.html
File metadata and controls
173 lines (166 loc) · 5.8 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
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
<meta name='viewport' content='width=device-width, initial-scale=1'/><!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>تطبيق عرض الأكواد</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
<style>
body {
font-family: 'Cairo', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
width: 100%;
max-width: 800px;
background: white;
padding: 20px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
border-radius: 10px;
text-align: center;
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
resize: vertical;
}
button {
padding: 10px 20px;
background: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-top: 10px;
transition: background 0.3s ease;
}
button:hover {
background: #0056b3;
}
.output {
display: none;
width: 100%;
height: 100vh;
position: relative;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
.icon {
color: #007bff;
font-size: 2rem;
margin-bottom: 10px;
}
.back-button {
position: absolute;
top: 10px;
left: 10px;
background: #dc3545;
}
.back-button:hover {
background: #c82333;
}
.python-output {
background: #f8f9fa;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-top: 10px;
text-align: left;
white-space: pre-wrap;
font-family: monospace;
}
@media (max-width: 600px) {
body {
padding: 10px;
}
.container {
padding: 15px;
}
button {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="icon"><i class="fas fa-code"></i></div>
<h2>تطبيق عرض الأكواد</h2>
<textarea id="htmlInput" placeholder="أدخل كود HTML هنا"></textarea>
<textarea id="cssInput" placeholder="أدخل كود CSS هنا"></textarea>
<textarea id="jsInput" placeholder="أدخل كود JavaScript هنا"></textarea>
<textarea id="pythonInput" placeholder="أدخل كود Python هنا"></textarea>
<button onclick="renderCode()">عرض الأكواد</button>
</div>
<div class="output">
<button class="back-button" onclick="goBack()"><i class="fas fa-arrow-left"></i> رجوع</button>
<iframe id="resultFrame"></iframe>
<div id="pythonResult" class="python-output"></div>
</div>
<script>
async function renderCode() {
const htmlCode = document.getElementById('htmlInput').value;
const cssCode = document.getElementById('cssInput').value;
const jsCode = document.getElementById('jsInput').value;
const pythonCode = document.getElementById('pythonInput').value;
if (!htmlCode && !cssCode && !jsCode && !pythonCode) {
alert("الرجاء إدخال كود على الأقل في أحد الحقول.");
return;
}
// عرض HTML, CSS, JS
const combinedCode = `
<style>${cssCode}</style>
${htmlCode}
<script>${jsCode}<\/script>
`;
const iframe = document.getElementById('resultFrame');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write(combinedCode);
iframeDoc.close();
// تنفيذ كود Python باستخدام Pyodide
if (pythonCode) {
await loadPyodide();
let output = "";
try {
const result = await pyodide.runPythonAsync(pythonCode);
output = result !== undefined ? result.toString() : "تم التنفيذ بنجاح بدون إخراج.";
} catch (error) {
output = `خطأ: ${error.message}`;
}
document.getElementById('pythonResult').innerText = output;
} else {
document.getElementById('pythonResult').innerText = "";
}
document.querySelector('.container').style.display = 'none';
document.querySelector('.output').style.display = 'block';
}
function goBack() {
document.querySelector('.container').style.display = 'block';
document.querySelector('.output').style.display = 'none';
}
// تحميل Pyodide عند بدء التطبيق
let pyodide;
async function loadPyodide() {
if (!pyodide) {
pyodide = await loadPyodide({ indexURL: "https://cdn.jsdelivr.net/pyodide/v0.23.4/full/" });
}
}
</script>
</body>
</html>