User
Psubhashish/common.js
< User:Psubhashish
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// Define the function to remove punctuation and words to new line
function removePunctuationAndWords() {
// Get the input text from the textarea element
var inputText = document.getElementById("input-text").value;
// Replace punctuation with a space, except for hyphen and apostrophe
var textWithSpaces = inputText.replace(/[।“”\(\)\[\]\{\}<>.,\/#!$%\^&\*;:{}=\-_`~]+/g, " ").replace(/(^[-])|([-]$)/g, "");
// Convert spaces to new line breaks
var textWithLineBreaks = textWithSpaces.replace(/[\s]+/g, "\n");
// Set the processed text as output text in the textarea element
document.getElementById("output-text").value = textWithLineBreaks;
}
// Define the function to remove Latin character words
function removeLatinWords() {
// Get the output text from the textarea element
var inputText = document.getElementById("output-text").value;
// Remove all characters except for the Bengali Unicode characters and space
var outputText = inputText.replace(/[^\u0B00-\u0B7F\s]+/g, "");
// Trim the processed text and set it as output text in the textarea element
document.getElementById("output-text").value = outputText.trim();
}
// Define the function to remove duplicates
function removeDuplicates() {
// Get the output text from the textarea element
var inputText = document.getElementById("output-text").value;
// Split the text into an array of words
var words = inputText.split(/\s+/);
// Remove duplicate words and create a new array of unique words
var uniqueWords = [];
for (var i = 0; i < words.length; i++) {
if (uniqueWords.indexOf(words[i]) === -1) {
uniqueWords.push(words[i]);
}
}
// Join the unique words into a string with new line breaks
var outputText = uniqueWords.join("\n");
// Trim the processed text and set it as output text in the textarea element
document.getElementById("output-text").value = outputText.trim();
}
// Define the function to sort alphabetically
function sortAlphabetically() {
// Get the output text from the textarea element
var inputText = document.getElementById("output-text").value;
// Split the text into an array of words
var words = inputText.split(/\s+/);
// Sort the array of words alphabetically
words.sort();
// Join the sorted words into a string with new line breaks
var outputText = words.join("\n");
// Trim the processed text and set it as output text in the textarea element
document.getElementById("output-text").value = outputText.trim();
}
// Define the function to replace new line breaks with hash symbol
function replaceLinesWithHash() {
// Get the output text from the textarea element
var inputText = document.getElementById("output-text").value;
// Replace new line breaks with hash symbol
var outputText = inputText.replace(/\n+/g, "#");
// Trim the processed text and set it as output text in the textarea element
document.getElementById("output-text").value = outputText.trim();
}
// Define the function to copy the output text to clipboard
function copyText() {
// Get the output text from the textarea element
var outputText = document.getElementById("output-text");
// Select the text in the textarea element
outputText.select();
}
// Copy the selected text to clipboard
document.execCommand("copy");