Interactive Code Execution in Lekhoniya
Introduction
Experience an enhanced level of interactivity on Lekhoniya with the introduction of Interactive Code Execution. This script, developed by Subham Mandal, enables users to execute custom JavaScript code snippets directly within the content. Let's dive into the details!
Overview
Interactive Code Execution
This script adds a dynamic layer to Lekhoniya by allowing users to execute custom JavaScript code snippets. Triggered by a specific combination of '@l' and 'l/' within the editable span, the entered code is processed and executed instantly.
document.addEventListener('keydown', function(event) {
if (event.key === 'Enter' || event.keyCode === 13) {
const editableSpan = document.getElementById('editableSpan');
const spanContent = editableSpan.innerHTML;
const lcStart = spanContent.indexOf('@l');
const lcEnd = spanContent.indexOf('l/');
if (lcStart !== -1 && lcEnd !== -1 && lcStart < lcEnd) {
const codeToExecute = spanContent.substring(lcStart + 2, lcEnd);
const replacedCode = codeToExecute.replace(/`id`/g, 'document.getElementById(')
.replace(/`b`/g, 'document.body')
.replace(/`bgc`/g, '.style.backgroundColor')
.replace(/`x`/g, 'document.getElementById("editableSpan")')
.replace(/`hide`/g, '.style.display="none"')
.replace(/`code`/g, 'document.write(');
const finalCode = replacedCode.replace(/`/g, '');
eval(finalCode);
}
}
});Usage Instructions
- Trigger Code Execution: Enter custom JavaScript code snippets within the editable span between '@l' and 'l/'.
- Execute Code: Press 'Enter', and the script will process and execute the entered code instantly.
Code Snippet Examples
Example 1: Change Background Color
@ldocument.getElementById('b').style.backgroundColor = 'blue'l/Example 2: Hide Editable Span
@l`x`.hide`l/Example 3: Execute Custom Code
@l`code`'<h1>Hello, Lekhoniya!</h1>'`l/Conclusion
Elevate your interaction with Lekhoniya using Interactive Code Execution. Developed by Subham Mandal, this script empowers users to integrate dynamic JavaScript functionalities seamlessly. Feel free to experiment and enhance your content with live code execution! For any queries or feedback, connect with Subham Mandal. Happy coding!