Convert Email Address to Duckduckgo Anonymous email format

Converts an email to duckgo anonymous email formatt

目前為 2025-01-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Convert Email Address to Duckduckgo Anonymous email format
// @namespace    http://tampermonkey.net/
// @author       aspen138
// @version      1.0
// @description  Converts an email to duckgo anonymous email formatt
// @match        https://mail.google.com/*
// @match        https://gmail.com/*
// @grant        none
// @icon         https://ssl.gstatic.com/ui/v1/icons/mail/rfr/gmail.ico
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';

    // 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 button
    const closeButton = document.createElement('button');
    closeButton.textContent = 'X';
    closeButton.style.position = 'absolute';
    closeButton.style.top = '5px';
    closeButton.style.right = '10px';
    closeButton.style.cursor = 'pointer';
    closeButton.style.border = 'none';
    closeButton.style.background = 'none';
    closeButton.style.fontSize = '16px';
    closeButton.addEventListener('click', function() {
        document.body.removeChild(container);
    });
    container.appendChild(closeButton);

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

    // Create 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';

    // Container for the "send email to who?" row
    const rowSendTo = document.createElement('div');
    rowSendTo.appendChild(labelSendTo);
    rowSendTo.appendChild(inputSendTo);

    // Create 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';

    // Container for the DDG mail row
    const rowDdgo = document.createElement('div');
    rowDdgo.appendChild(labelDdgo);
    rowDdgo.appendChild(inputDdgo);

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

    // Create an input field for the output (read-only)
    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';

    // Container for the output row
    const rowOutput = document.createElement('div');
    // rowOutput.style.marginTop = '5px';
    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'; // keep space for feedback text
    feedback.textContent = '';

    // Conversion function
    buttonConvert.addEventListener('click', function() {
        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.';
        }

        if (errorMessage) {
            feedback.textContent = errorMessage;
            outputEmail.value = '';
            return;
        }

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

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

    container.appendChild(formWrapper);
    document.body.appendChild(container);
})();