User
Difference between revisions of "Psubhashish/common.js"
< User:Psubhashish
Psubhashish (talk | contribs) (Created page with "→**************************************************************************: // Description: Adds a personal generator of words list to the RecordWizard // Usage: Copy thi...") |
Psubhashish (talk | contribs) |
||
Line 1: | Line 1: | ||
− | / | + | // 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"); |
Latest revision as of 13:01, 14 March 2023
// 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");