Convert Email Address to Duckduckgo Anonymous email format

Converts an email to duckgo anonymous email format, now with minimize functionality

目前为 2025-03-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Convert Email Address to Duckduckgo Anonymous email format
// @namespace    http://tampermonkey.net/
// @author       aspen138
// @version      1.1.2
// @description  Converts an email to duckgo anonymous email format, now with minimize functionality
// @match        https://mail.google.com/*
// @match        https://gmail.com/*
// @match        https://outlook.live.com/*
// @match        https://outlook.com/*
// @match        https://mail.yahoo.com/*
// @match        https://yahoo.com/mail/*
// @match        https://mail.qq.com/*
// @match        https://exmail.qq.com/*
// @match        https://proton.me/*
// @match        https://mail.proton.me/*
// @match        https://icloud.com/mail/*
// @match        https://mail.apple.com/*
// @match        https://zoho.com/mail/*
// @match        https://mail.zoho.com/*
// @match        https://mail.aol.com/*
// @match        https://aol.com/mail/*
// @match        https://www.mail.com/*
// @match        https://email.mail.com/*
// @match        https://mail.yandex.com/*
// @match        https://yandex.com/mail/*
// @match        https://mail.163.com/*
// @match        https://www.163.com/mail/*
// @match        https://mail.126.com/*
// @match        https://www.126.com/*
// @match        https://mail.sina.com/*
// @match        https://mail.sina.com.cn/*
// @match        https://gmx.com/*
// @match        https://mail.gmx.com/*
// @match        https://fastmail.com/*
// @match        https://mail.fastmail.com/*
// @icon         https://ssl.gstatic.com/ui/v1/icons/mail/rfr/gmail.ico
// @license      MIT
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    // Retrieve a stored value for demonstration (not essential for minimizing logic)
    const testStoredSendTo = GM_getValue('whatever', '');
    console.log("testStoredSendTo", testStoredSendTo);

    // Create a container for the floating box
    const container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.bottom = '20px';
    container.style.left = '20px';
    container.style.zIndex = '9999';
    container.style.padding = '10px';
    container.style.backgroundColor = '#fff';
    container.style.border = '1px solid #ccc';
    container.style.borderRadius = '5px';
    container.style.boxShadow = '0 0 5px rgba(0,0,0,0.3)';
    container.style.fontFamily = 'Arial, sans-serif';
    container.style.maxWidth = '280px';

    // Title or heading
    const heading = document.createElement('h4');
    heading.textContent = 'Email Converter';
    heading.style.margin = '0 0 10px 0';
    container.appendChild(heading);

    // Close (minimize) button
    const minimizeButton = document.createElement('button');
    minimizeButton.textContent = 'X';
    minimizeButton.style.position = 'absolute';
    minimizeButton.style.top = '5px';
    minimizeButton.style.right = '10px';
    minimizeButton.style.cursor = 'pointer';
    minimizeButton.style.border = 'none';
    minimizeButton.style.background = 'none';
    minimizeButton.style.fontSize = '16px';
    container.appendChild(minimizeButton);

    // This button will appear when the container is minimized
    const restoreButton = document.createElement('button');
    restoreButton.textContent = 'Email Converter';
    restoreButton.style.position = 'fixed';
    restoreButton.style.left = '0';
    restoreButton.style.bottom = '20px';
    restoreButton.style.zIndex = '9999';
    restoreButton.style.padding = '6px 12px';
    restoreButton.style.cursor = 'pointer';
    restoreButton.style.border = '1px solid #ccc';
    restoreButton.style.borderRadius = '5px';
    restoreButton.style.fontFamily = 'Arial, sans-serif';
    restoreButton.style.backgroundColor = '#fff';
    restoreButton.style.boxShadow = '0 0 5px rgba(0,0,0,0.3)';
    // Initially hidden
    // restoreButton.style.display = 'none';
    container.style.display = 'none';
    restoreButton.style.display = 'block';
    document.body.appendChild(restoreButton);

    // When the user clicks the "X", hide the container and show the restore button
    minimizeButton.addEventListener('click', () => {
        container.style.display = 'none';
        restoreButton.style.display = 'block';
    });

    // When the user clicks restore, show the container and hide the restore button
    restoreButton.addEventListener('click', () => {
        container.style.display = 'block';
        restoreButton.style.display = 'none';
    });

    // Wrapper to neatly organize form elements
    const formWrapper = document.createElement('div');
    formWrapper.style.display = 'flex';
    formWrapper.style.flexDirection = 'column';
    formWrapper.style.gap = '5px';

    // Retrieve stored values (if any)
    const storedSendTo = GM_getValue('converterSendTo', '');
    const storedDdgo = GM_getValue('converterDdgo', '');

    // Label and input for "send email to who?"
    const labelSendTo = document.createElement('label');
    labelSendTo.textContent = 'Send email to who: ';
    labelSendTo.style.marginRight = '10px';

    const inputSendTo = document.createElement('input');
    inputSendTo.type = 'text';
    inputSendTo.placeholder = 'e.g. [email protected]';
    inputSendTo.style.width = '250px';
    inputSendTo.value = storedSendTo;

    const rowSendTo = document.createElement('div');
    rowSendTo.appendChild(labelSendTo);
    rowSendTo.appendChild(inputSendTo);

    // Label and input for "your ddgo mail?"
    const labelDdgo = document.createElement('label');
    labelDdgo.textContent = 'Your DuckduckGo address: ';
    labelDdgo.style.marginRight = '10px';

    const inputDdgo = document.createElement('input');
    inputDdgo.type = 'text';
    inputDdgo.placeholder = 'e.g. [email protected]';
    inputDdgo.style.width = '250px';
    inputDdgo.value = storedDdgo;

    const rowDdgo = document.createElement('div');
    rowDdgo.appendChild(labelDdgo);
    rowDdgo.appendChild(inputDdgo);

    // Convert button
    const buttonConvert = document.createElement('button');
    buttonConvert.textContent = 'Convert';
    buttonConvert.style.marginRight = '10px';
    buttonConvert.style.cursor = 'pointer';
    buttonConvert.style.width = '250px';

    // Output field for converted email
    const labelOutput = document.createElement('label');
    labelOutput.textContent = 'Converted: ';
    labelOutput.style.marginRight = '10px';

    const outputEmail = document.createElement('input');
    outputEmail.type = 'text';
    outputEmail.readOnly = true;
    outputEmail.style.width = '250px';

    const rowOutput = document.createElement('div');
    rowOutput.appendChild(labelOutput);
    rowOutput.appendChild(outputEmail);

    // Feedback or error message area
    const feedback = document.createElement('p');
    feedback.style.color = 'red';
    feedback.style.fontSize = '14px';
    feedback.style.margin = '5px 0 0 0';
    feedback.style.minHeight = '18px';
    feedback.textContent = '';

    // Conversion function
    buttonConvert.addEventListener('click', () => {
        const originalEmail = inputSendTo.value.trim();
        const ddgoEmail = inputDdgo.value.trim();
        let errorMessage = '';

        // Simple validations
        if (!originalEmail) {
            errorMessage = 'Please enter an email address to convert.';
        } else if (!ddgoEmail) {
            errorMessage = 'Please enter your DDG address.';
        }

        // Handle any errors
        if (errorMessage) {
            feedback.textContent = errorMessage;
            outputEmail.value = '';
            return;
        }

        // Replace '@' with '_at_' and append the ddgo email
        const converted = originalEmail.replace(/@/g, '_at_') + '_' + ddgoEmail;
        outputEmail.value = converted;
        feedback.textContent = '';

        // Save inputs to Tampermonkey storage
        GM_setValue('converterSendTo', originalEmail);
        GM_setValue('converterDdgo', ddgoEmail);
    });

    // Assemble elements in the container
    formWrapper.appendChild(rowSendTo);
    formWrapper.appendChild(rowDdgo);
    formWrapper.appendChild(buttonConvert);
    formWrapper.appendChild(rowOutput);
    formWrapper.appendChild(feedback);

    container.appendChild(formWrapper);

    // Finally, attach the container to document body
    document.body.appendChild(container);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址