make a tampermonkey script that looks througgh the entire dom for strings that match a…
- User
make a tampermonkey script that looks througgh the entire dom for strings that match a regex, if found gets them all and outputs them into the console: the regex ill input myself you can put a placeholder regex.
- Assistant
Certainly! Here's an example Tampermonkey script that searches for strings in the DOM that match a given regular expression and outputs them to the console:
// ==UserScript== // @name String Search Script // @namespace http://tampermonkey.net/ // @version 1.0 // @description Searches for strings in the DOM that match a regex and outputs them to the console. // @author Your Name // @match http://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Define your regular expression here (in the format /yourRegex/): const regex = /yourRegex/; // Recursive function to search for matching strings in the DOM function searchDOM(element) { // Iterate over child nodes of the current element element.childNodes.forEach(function(node) { if (node.nodeType === Node.TEXT_NODE && regex.test(node.textContent)) { // Found a match, output to console console.log(node.textContent); } else if (node.nodeType === Node.ELEMENT_NODE) { // Recursively search child elements searchDOM(node); } }); } // Start the search from the document's root element searchDOM(document.documentElement); })(); - User
instead of outputting one by one concatanate them by new lines and then output.
- Assistant
Certainly! Here's an updated version of the Tampermonkey script that concatenates the matched strings with new lines before outputting them to the console:
// ==UserScript== // @name String Search Script // @namespace http://tampermonkey.net/ // @version 1.0 // @description Searches for strings in the DOM that match a regex and outputs them to the console. // @author Your Name // @match http://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Define your regular expression here (in the format /yourRegex/): const regex = /yourRegex/; // Recursive function to search for matching strings in the DOM function searchDOM(element, result) { element.childNodes.forEach(function(node) { if (node.nodeType === Node.TEXT_NODE && regex.test(node.textContent)) { // Found a match, add to the result array result.push(node.textContent); } else if (node.nodeType === Node.ELEMENT_NODE) { // Recursively search child elements searchDOM(node, result); } }); } // Start the search from the document's root element const result = []; searchDOM(document.documentElement, result); // Concatenate the matched strings with new lines const output = result.join('\n'); // Output the concatenated strings to the console console.log(output); })(); - User
my regex seems to be getting some random javascript that includes an email instead of just the email. /(?:[a-z0-9+!#%&'+/=?^_`{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gi
- Assistant