Convert Email Address to Duckduckgo Anonymous email format

Converts an email to duckgo anonymous email formatt

当前为 2025-01-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Convert Email Address to Duckduckgo Anonymous email format
  3. // @namespace http://tampermonkey.net/
  4. // @author aspen138
  5. // @version 1.0
  6. // @description Converts an email to duckgo anonymous email formatt
  7. // @match https://mail.google.com/*
  8. // @match https://gmail.com/*
  9. // @grant none
  10. // @icon https://ssl.gstatic.com/ui/v1/icons/mail/rfr/gmail.ico
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Create a container for the floating box
  19. const container = document.createElement('div');
  20. container.style.position = 'fixed';
  21. container.style.bottom = '20px';
  22. container.style.left = '20px';
  23. container.style.zIndex = '9999';
  24. container.style.padding = '10px';
  25. container.style.backgroundColor = '#fff';
  26. container.style.border = '1px solid #ccc';
  27. container.style.borderRadius = '5px';
  28. container.style.boxShadow = '0 0 5px rgba(0, 0, 0, 0.3)';
  29. container.style.fontFamily = 'Arial, sans-serif';
  30. container.style.maxWidth = '280px';
  31.  
  32. // Title or heading
  33. const heading = document.createElement('h4');
  34. heading.textContent = 'Email Converter';
  35. heading.style.margin = '0 0 10px 0';
  36. container.appendChild(heading);
  37.  
  38. // Close button
  39. const closeButton = document.createElement('button');
  40. closeButton.textContent = 'X';
  41. closeButton.style.position = 'absolute';
  42. closeButton.style.top = '5px';
  43. closeButton.style.right = '10px';
  44. closeButton.style.cursor = 'pointer';
  45. closeButton.style.border = 'none';
  46. closeButton.style.background = 'none';
  47. closeButton.style.fontSize = '16px';
  48. closeButton.addEventListener('click', function() {
  49. document.body.removeChild(container);
  50. });
  51. container.appendChild(closeButton);
  52.  
  53. // Wrapper to neatly organize form elements
  54. const formWrapper = document.createElement('div');
  55. formWrapper.style.display = 'flex';
  56. formWrapper.style.flexDirection = 'column';
  57. formWrapper.style.gap = '5px'; // spacing between items
  58.  
  59. // Create label and input for "send email to who?"
  60. const labelSendTo = document.createElement('label');
  61. labelSendTo.textContent = 'Send email to who: ';
  62. labelSendTo.style.marginRight = '10px';
  63.  
  64. const inputSendTo = document.createElement('input');
  65. inputSendTo.type = 'text';
  66. inputSendTo.placeholder = 'e.g. 123@qq.com';
  67. inputSendTo.style.width = '250px';
  68.  
  69. // Container for the "send email to who?" row
  70. const rowSendTo = document.createElement('div');
  71. rowSendTo.appendChild(labelSendTo);
  72. rowSendTo.appendChild(inputSendTo);
  73.  
  74. // Create label and input for "your ddgo mail?"
  75. const labelDdgo = document.createElement('label');
  76. labelDdgo.textContent = 'Your DuckduckGo address: ';
  77. labelDdgo.style.marginRight = '10px';
  78.  
  79. const inputDdgo = document.createElement('input');
  80. inputDdgo.type = 'text';
  81. inputDdgo.placeholder = 'e.g. dd@duck.com';
  82. inputDdgo.style.width = '250px';
  83.  
  84. // Container for the DDG mail row
  85. const rowDdgo = document.createElement('div');
  86. rowDdgo.appendChild(labelDdgo);
  87. rowDdgo.appendChild(inputDdgo);
  88.  
  89. // Create a button to trigger conversion
  90. const buttonConvert = document.createElement('button');
  91. buttonConvert.textContent = 'Convert';
  92. buttonConvert.style.marginRight = '10px';
  93. buttonConvert.style.cursor = 'pointer';
  94. buttonConvert.style.width = '250px';
  95.  
  96. // Create an input field for the output (read-only)
  97. const labelOutput = document.createElement('label');
  98. labelOutput.textContent = 'Converted: ';
  99. labelOutput.style.marginRight = '10px';
  100.  
  101. const outputEmail = document.createElement('input');
  102. outputEmail.type = 'text';
  103. outputEmail.readOnly = true;
  104. outputEmail.style.width = '250px';
  105.  
  106. // Container for the output row
  107. const rowOutput = document.createElement('div');
  108. // rowOutput.style.marginTop = '5px';
  109. rowOutput.appendChild(labelOutput);
  110. rowOutput.appendChild(outputEmail);
  111.  
  112. // Feedback or error message area
  113. const feedback = document.createElement('p');
  114. feedback.style.color = 'red';
  115. feedback.style.fontSize = '14px';
  116. feedback.style.margin = '5px 0 0 0';
  117. feedback.style.minHeight = '18px'; // keep space for feedback text
  118. feedback.textContent = '';
  119.  
  120. // Conversion function
  121. buttonConvert.addEventListener('click', function() {
  122. const originalEmail = inputSendTo.value.trim();
  123. const ddgoEmail = inputDdgo.value.trim();
  124. let errorMessage = '';
  125.  
  126. // Simple validations
  127. if (!originalEmail) {
  128. errorMessage = 'Please enter an email address to convert.';
  129. } else if (!ddgoEmail) {
  130. errorMessage = 'Please enter your DDG address.';
  131. }
  132.  
  133. if (errorMessage) {
  134. feedback.textContent = errorMessage;
  135. outputEmail.value = '';
  136. return;
  137. }
  138.  
  139. // Replace all '@' with '_at_' and append the ddgo email
  140. const converted = originalEmail.replace(/@/g, '_at_') + '_' + ddgoEmail;
  141. outputEmail.value = converted;
  142. feedback.textContent = ''; // clear any previous error message
  143. });
  144.  
  145. // Assemble elements in the container
  146. formWrapper.appendChild(rowSendTo);
  147. formWrapper.appendChild(rowDdgo);
  148. formWrapper.appendChild(buttonConvert);
  149. formWrapper.appendChild(rowOutput);
  150. formWrapper.appendChild(feedback);
  151.  
  152. container.appendChild(formWrapper);
  153. document.body.appendChild(container);
  154. })();