Lekhoniya: A Dynamic Text Formatting Script
Introduction
Welcome to the world of Lekhoniya - a dynamic text formatting script designed to enhance your web editing experience. Developed by the talented programmer Subham Mandal, this script empowers users to apply rich formatting styles seamlessly.
Overview
The Console Magic
The script incorporates a unique console logging feature. onessssweb users will appreciate the interactive console, providing real-time feedback on their actions. The console, housed in the "console-card" element, displays messages and actions, making debugging and monitoring a breeze.
const consoleLog = console.log;
const card = document.getElementById("console-card");
console.log = function () {
for (let i = 0; i < arguments.length; i++) {
const message = arguments[i];
const p = document.createElement('p');
p.textContent = message;
card.appendChild(p);
}
consoleLog.apply(console, arguments);
card.style.opacity = 1;
if (hideTimeout) {
clearTimeout(hideTimeout);
}
hideTimeout = setTimeout(() => {
card.style.opacity = 0; // Hide the card
setTimeout(() => {
card.innerHTML = '';
}, 300);
}, 5000);
};Text Formatting Wizardry
Lekhoniya introduces an innovative text formatting mechanism. The function applyFormatting enables users to customize text color, font weight, family, size, and decoration. It intelligently handles both selected and unselected text, providing a seamless editing experience.
function applyFormatting(color, fontWeight, fontFamily, fontSize, textDecoration) {
saveSelection();
var span = document.querySelector('.main');
var newNode = document.createElement('span');
newNode.style.color = color;
newNode.style.fontWeight = fontWeight;
newNode.style.fontFamily = fontFamily;
newNode.style.fontSize = fontSize;
newNode.style.textDecoration = textDecoration;
if (selectedRange.toString().length > 0) {
newNode.appendChild(selectedRange.extractContents());
selectedRange.insertNode(newNode);
} else {
newNode.innerHTML = '​'; // Zero-width space
selectedRange.insertNode(newNode);
selectedRange.setStartAfter(newNode);
selectedRange.setEndAfter(newNode);
restoreSelection();
}
}Background Brilliance
The script doesn't stop at text formatting. Users can also apply background colors effortlessly with the applyBackgroundColor function. Highlight your content with a splash of color using this powerful feature.
function applyBackgroundColor(color) {
saveSelection();
var span = document.querySelector('.main');
var newNode = document.createElement('span');
newNode.style.backgroundColor = color;
if (selectedRange.toString().length > 0) {
newNode.appendChild(selectedRange.extractContents());
selectedRange.insertNode(newNode);
} else {
newNode.innerHTML = '​'; // Zero-width space
selectedRange.insertNode(newNode);
selectedRange.setStartAfter(newNode);
selectedRange.setEndAfter(newNode);
restoreSelection();
}
}Usage Instructions
- Text Formatting: Highlight the desired text and call
applyFormattingwith your preferred styles. - Background Color: Select text or position the cursor, then invoke
applyBackgroundColorwith the desired color.
Conclusion
Embrace the power of Lekhoniya and elevate your web editing experience. The brilliance of this script is a testament to the programming prowess of Subham Mandal. Dive in, explore, and let your creativity flow! onessssweb users, rejoice!
Feel free to connect with Subham Mandal for any inquiries or enhancements to this incredible script.