Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constants for configurable values
- const MAX_ELEMENTS = 100;
- const REMOVAL_TEXT = "@amir0.eth";
- // Array to store text
- var textArray = [];
- // Select all elements with the class .shrink
- var shrinkElements = document.querySelectorAll('.shrink');
- // Iterate over each element
- shrinkElements.forEach(function(element) {
- // Get the second <span> element within the current element
- var secondSpan = element.children[1];
- // Check if secondSpan exists and contains an <a> tag
- if (secondSpan && secondSpan.querySelector('a')) {
- // Get the text content inside the <a> tag inside the second <span>
- var text = secondSpan.querySelector('a').textContent;
- // Remove certain element based on text content
- if (text !== REMOVAL_TEXT) {
- // Add text to array if it's not already present
- if (!textArray.includes(text)) {
- textArray.push(text);
- }
- } else {
- // Remove the element from the DOM
- element.remove();
- }
- }
- });
- // Remove duplicates by converting array to set and back to array
- textArray = Array.from(new Set(textArray));
- // Shuffle the array
- textArray.sort(() => Math.random() - 0.5);
- // Keep only the first MAX_ELEMENTS elements if there are more than MAX_ELEMENTS
- textArray = textArray.slice(0, MAX_ELEMENTS);
- // If there are less than MAX_ELEMENTS elements, continue adding unique elements until it reaches MAX_ELEMENTS
- while (textArray.length < MAX_ELEMENTS) {
- var uniqueText = getRandomUniqueText();
- if (!textArray.includes(uniqueText)) {
- textArray.push(uniqueText);
- }
- }
- // Function to generate a random unique text
- function getRandomUniqueText() {
- // Example: Generate a random string
- return "RandomUniqueText" + Math.floor(Math.random() * 100000);
- }
- // Combine all texts together with space
- var combinedText = textArray.join(' ');
- // Output the combined text
- console.log(combinedText);
Advertisement
Comments
-
- // Constants for configurable values
- const MAX_ELEMENTS = 100;
- const REMOVAL_TEXT = "@daveriser";
- // Array to store text
- var textArray = [];
- // Select all elements with the class .shrink
- var shrinkElements = document.querySelectorAll('.shrink');
- // Iterate over each element
- shrinkElements.forEach(function(element) {
- // Get the second <span> element within the current element
- var secondSpan = element.children[1];
- // Check if secondSpan exists and contains an <a> tag
- if (secondSpan && secondSpan.querySelector('a')) {
- // Get the text content inside the <a> tag inside the second <span>
- var text = secondSpan.querySelector('a').textContent;
- // Remove certain element based on text content
- if (text !== REMOVAL_TEXT) {
- // Add text to array if it's not already present
- if (!textArray.includes(text)) {
- textArray.push(text);
- }
- } else {
- // Remove the element from the DOM
- element.remove();
- }
- }
- });
- // Remove duplicates by converting array to set and back to array
- textArray = Array.from(new Set(textArray));
- // Shuffle the array
- textArray.sort(() => Math.random() - 0.5);
- // Keep only the first MAX_ELEMENTS elements if there are more than MAX_ELEMENTS
- textArray = textArray.slice(0, MAX_ELEMENTS);
- // If there are less than MAX_ELEMENTS elements, continue adding unique elements until it reaches MAX_ELEMENTS
- while (textArray.length < MAX_ELEMENTS) {
- var uniqueText = getRandomUniqueText();
- if (!textArray.includes(uniqueText)) {
- textArray.push(uniqueText);
- }
- }
- // Function to generate a random unique text
- function getRandomUniqueText() {
- // Example: Generate a random string
- return "RandomUniqueText" + Math.floor(Math.random() * 100000);
- }
- // Combine all texts together with space
- var combinedText = textArray.join(' ');
- // Output the combined text
- console.log(combinedText);
Add Comment
Please, Sign In to add comment
Advertisement