Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Update salam-online.html
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax authored Sep 8, 2024
1 parent ba927b6 commit a324e69
Showing 1 changed file with 1 addition and 110 deletions.
111 changes: 1 addition & 110 deletions salam-online.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,116 +17,7 @@
<iframe></iframe>
<pre></pre>

<script>
const codeTextArea = document.querySelector('#code');
const executeButton = document.querySelector('#execute');
const outputPre = document.querySelector('pre');
const iframe = document.querySelector('iframe');

if(localStorage.getItem("cache-code")){
codeTextArea.value = localStorage.getItem("cache-code")
}

codeTextArea.addEventListener("input", function () {
localStorage.setItem("cache-code", codeTextArea.value);
})

const args = ['code', ''];
let isReady = false;

var Module = {
noInitialRun: true,
onRuntimeInitialized: () => {
console.log('Salam loaded successfully');
isReady = true;
executeButton.disabled = false;

if (codeTextArea.value.toString().trim() !== '') {
runSalam();
}
},
print: (text) => {
console.log(text);
}
};

function captureOutput(arguments) {
if (iframe.style.right === "50%") {
iframe.style.right = "150%"
} else if (iframe.style.right === "150%") {
iframe.style.right = "50%"
} else {
iframe.style.right = "50%"
}
if (outputPre) {
outputPre.textContent = '';
}

let output = '';

const originalConsoleLog = console.log;
console.log = function (text) {
output += text + '\n';
};

callMain(arguments);

console.log = originalConsoleLog;

if (outputPre) {
outputPre.textContent = output;

const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDocument) {
iframeDocument.open();
iframeDocument.write(output);
iframeDocument.close();
}
}

return output;
}

function runSalam() {
console.log('Running Salam code...');
const code = codeTextArea.value.toString().trim();

if (!code) {
alert('Code is empty! Please enter Salam code.');
return;
}

args[1] = code;
console.log('Calling Salam with arguments:', args);

if (isReady) {
captureOutput(args);
} else {
console.log('Salam runtime not ready. Please wait...');
}
}

executeButton.addEventListener('click', () => {
console.log('Button clicked!');
runSalam();
});

codeTextArea.addEventListener('keydown', function (event) {
if (event.key === 'Tab') {
event.preventDefault();
const textarea = this;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
textarea.value = textarea.value.substring(0, start) + '\t' + textarea.value.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + 1;
}
});

const script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'salam-wa.js';
document.body.appendChild(script);
</script>
<script src="script/script.js"></script>
</body>

</html>

0 comments on commit a324e69

Please sign in to comment.