目录

TamperMonkey油猴插件直达

谷歌搜索结果页含URLs时全部自动下载为txt

				
					// ==UserScript==
// @name         Extract Main URLs from Google Search Results
// @namespace    https://wordpressbin.com
// @version      0.1
// @description  Extract main URLs from Google search results and download them as a text file
// @author       Bin
// @match        https://www.google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract main URLs from a string
    function extractMainURLs(text) {
        // Define a regular expression pattern to match main URLs
        var pattern = /(https?:\/\/(?:www\.)?[^\s/]+)(?:\s+\w+\s+L:\s+\w+)?/g;
        // Match URLs using the pattern
        var matches = text.match(pattern);
        // Filter out non-main URLs
        if (matches) {
            return matches.filter(function(url) {
                return !url.includes('google.com');
            });
        } else {
            return [];
        }
    }

    // Function to download text as a file
    function downloadText(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);

        element.style.display = 'none';
        document.body.appendChild(element);

        element.click();

        document.body.removeChild(element);
    }

    // Main function to extract main URLs from Google search results and download as text
    function extractAndDownloadMainURLs() {
        // Get all search result elements
        var searchResults = document.querySelectorAll('.tF2Cxc');

        // Initialize an array to store all found main URLs
        var mainURLs = [];

        // Loop through each search result
        searchResults.forEach(function(result) {
            // Get the URL from the 'href' attribute of the search result link
            var resultURL = result.querySelector('a[href^="http"]').getAttribute('href');
            // Add found main URL to the array
            if (resultURL) {
                mainURLs.push(resultURL);
            }
        });

        // Join all main URLs into a single string separated by newline characters
        var mainURLsText = mainURLs.join('\n');

        // Download the main URLs as a text file
        downloadText('main_urls.txt', mainURLsText);
    }

    // Call the main function when the page is loaded
    extractAndDownloadMainURLs();
})();

				
			

谷歌搜索结果页含Emails时全部自动下载为txt

				
					// ==UserScript==
// @name         Extract Emails from Google Search Results
// @namespace    https://wordpressbin.com
// @version      0.1
// @description  Extract emails from Google search results and download them as a text file
// @author       Bin
// @match        https://www.google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract emails from a string
    function extractEmails(text) {
        return text.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g);
    }

    // Function to download text as a file
    function downloadText(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);

        element.style.display = 'none';
        document.body.appendChild(element);

        element.click();

        document.body.removeChild(element);
    }

    // Main function to extract emails from Google search results and download as text
    function extractAndDownloadEmails() {
        // Get all search result elements
        var searchResults = document.querySelectorAll('.tF2Cxc');

        // Initialize an array to store all found emails
        var emails = [];

        // Loop through each search result
        searchResults.forEach(function(result) {
            // Extract text from the search result
            var resultText = result.textContent;
            // Extract emails from the text
            var resultEmails = extractEmails(resultText);
            // Add found emails to the array
            if (resultEmails) {
                emails = emails.concat(resultEmails);
            }
        });

        // Join all emails into a single string separated by newline characters
        var emailsText = emails.join('\n');

        // Download the emails as a text file
        downloadText('emails.txt', emailsText);
    }

    // Call the main function when the page is loaded
    window.addEventListener('load', extractAndDownloadEmails);
})();