Convert Email Address to Duckduckgo Anonymous email format

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

目前为 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.1.2
  6. // @description Converts an email to duckgo anonymous email format, now with minimize functionality
  7. // @match https://mail.google.com/*
  8. // @match https://gmail.com/*
  9. // @icon https://ssl.gstatic.com/ui/v1/icons/mail/rfr/gmail.ico
  10. // @license MIT
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Retrieve a stored value for demonstration (not essential for minimizing logic)
  19. const testStoredSendTo = GM_getValue('whatever', '');
  20. console.log("testStoredSendTo", testStoredSendTo);
  21.  
  22. // Create a container for the floating box
  23. const container = document.createElement('div');
  24. container.style.position = 'fixed';
  25. container.style.bottom = '20px';
  26. container.style.left = '20px';
  27. container.style.zIndex = '9999';
  28. container.style.padding = '10px';
  29. container.style.backgroundColor = '#fff';
  30. container.style.border = '1px solid #ccc';
  31. container.style.borderRadius = '5px';
  32. container.style.boxShadow = '0 0 5px rgba(0,0,0,0.3)';
  33. container.style.fontFamily = 'Arial, sans-serif';
  34. container.style.maxWidth = '280px';
  35.  
  36. // Title or heading
  37. const heading = document.createElement('h4');
  38. heading.textContent = 'Email Converter';
  39. heading.style.margin = '0 0 10px 0';
  40. container.appendChild(heading);
  41.  
  42. // Close (minimize) button
  43. const minimizeButton = document.createElement('button');
  44. minimizeButton.textContent = 'X';
  45. minimizeButton.style.position = 'absolute';
  46. minimizeButton.style.top = '5px';
  47. minimizeButton.style.right = '10px';
  48. minimizeButton.style.cursor = 'pointer';
  49. minimizeButton.style.border = 'none';
  50. minimizeButton.style.background = 'none';
  51. minimizeButton.style.fontSize = '16px';
  52. container.appendChild(minimizeButton);
  53.  
  54. // This button will appear when the container is minimized
  55. const restoreButton = document.createElement('button');
  56. restoreButton.textContent = 'Email Converter';
  57. restoreButton.style.position = 'fixed';
  58. restoreButton.style.left = '0';
  59. restoreButton.style.bottom = '20px';
  60. restoreButton.style.zIndex = '9999';
  61. restoreButton.style.padding = '6px 12px';
  62. restoreButton.style.cursor = 'pointer';
  63. restoreButton.style.border = '1px solid #ccc';
  64. restoreButton.style.borderRadius = '5px';
  65. restoreButton.style.fontFamily = 'Arial, sans-serif';
  66. restoreButton.style.backgroundColor = '#fff';
  67. restoreButton.style.boxShadow = '0 0 5px rgba(0,0,0,0.3)';
  68. // Initially hidden
  69. // restoreButton.style.display = 'none';
  70. container.style.display = 'none';
  71. restoreButton.style.display = 'block';
  72. document.body.appendChild(restoreButton);
  73.  
  74. // When the user clicks the "X", hide the container and show the restore button
  75. minimizeButton.addEventListener('click', () => {
  76. container.style.display = 'none';
  77. restoreButton.style.display = 'block';
  78. });
  79.  
  80. // When the user clicks restore, show the container and hide the restore button
  81. restoreButton.addEventListener('click', () => {
  82. container.style.display = 'block';
  83. restoreButton.style.display = 'none';
  84. });
  85.  
  86. // Wrapper to neatly organize form elements
  87. const formWrapper = document.createElement('div');
  88. formWrapper.style.display = 'flex';
  89. formWrapper.style.flexDirection = 'column';
  90. formWrapper.style.gap = '5px';
  91.  
  92. // Retrieve stored values (if any)
  93. const storedSendTo = GM_getValue('converterSendTo', '');
  94. const storedDdgo = GM_getValue('converterDdgo', '');
  95.  
  96. // Label and input for "send email to who?"
  97. const labelSendTo = document.createElement('label');
  98. labelSendTo.textContent = 'Send email to who: ';
  99. labelSendTo.style.marginRight = '10px';
  100.  
  101. const inputSendTo = document.createElement('input');
  102. inputSendTo.type = 'text';
  103. inputSendTo.placeholder = 'e.g. 123@qq.com';
  104. inputSendTo.style.width = '250px';
  105. inputSendTo.value = storedSendTo;
  106.  
  107. const rowSendTo = document.createElement('div');
  108. rowSendTo.appendChild(labelSendTo);
  109. rowSendTo.appendChild(inputSendTo);
  110.  
  111. // Label and input for "your ddgo mail?"
  112. const labelDdgo = document.createElement('label');
  113. labelDdgo.textContent = 'Your DuckduckGo address: ';
  114. labelDdgo.style.marginRight = '10px';
  115.  
  116. const inputDdgo = document.createElement('input');
  117. inputDdgo.type = 'text';
  118. inputDdgo.placeholder = 'e.g. dd@duck.com';
  119. inputDdgo.style.width = '250px';
  120. inputDdgo.value = storedDdgo;
  121.  
  122. const rowDdgo = document.createElement('div');
  123. rowDdgo.appendChild(labelDdgo);
  124. rowDdgo.appendChild(inputDdgo);
  125.  
  126. // Convert button
  127. const buttonConvert = document.createElement('button');
  128. buttonConvert.textContent = 'Convert';
  129. buttonConvert.style.marginRight = '10px';
  130. buttonConvert.style.cursor = 'pointer';
  131. buttonConvert.style.width = '250px';
  132.  
  133. // Output field for converted email
  134. const labelOutput = document.createElement('label');
  135. labelOutput.textContent = 'Converted: ';
  136. labelOutput.style.marginRight = '10px';
  137.  
  138. const outputEmail = document.createElement('input');
  139. outputEmail.type = 'text';
  140. outputEmail.readOnly = true;
  141. outputEmail.style.width = '250px';
  142.  
  143. const rowOutput = document.createElement('div');
  144. rowOutput.appendChild(labelOutput);
  145. rowOutput.appendChild(outputEmail);
  146.  
  147. // Feedback or error message area
  148. const feedback = document.createElement('p');
  149. feedback.style.color = 'red';
  150. feedback.style.fontSize = '14px';
  151. feedback.style.margin = '5px 0 0 0';
  152. feedback.style.minHeight = '18px';
  153. feedback.textContent = '';
  154.  
  155. // Conversion function
  156. buttonConvert.addEventListener('click', () => {
  157. const originalEmail = inputSendTo.value.trim();
  158. const ddgoEmail = inputDdgo.value.trim();
  159. let errorMessage = '';
  160.  
  161. // Simple validations
  162. if (!originalEmail) {
  163. errorMessage = 'Please enter an email address to convert.';
  164. } else if (!ddgoEmail) {
  165. errorMessage = 'Please enter your DDG address.';
  166. }
  167.  
  168. // Handle any errors
  169. if (errorMessage) {
  170. feedback.textContent = errorMessage;
  171. outputEmail.value = '';
  172. return;
  173. }
  174.  
  175. // Replace '@' with '_at_' and append the ddgo email
  176. const converted = originalEmail.replace(/@/g, '_at_') + '_' + ddgoEmail;
  177. outputEmail.value = converted;
  178. feedback.textContent = '';
  179.  
  180. // Save inputs to Tampermonkey storage
  181. GM_setValue('converterSendTo', originalEmail);
  182. GM_setValue('converterDdgo', ddgoEmail);
  183. });
  184.  
  185. // Assemble elements in the container
  186. formWrapper.appendChild(rowSendTo);
  187. formWrapper.appendChild(rowDdgo);
  188. formWrapper.appendChild(buttonConvert);
  189. formWrapper.appendChild(rowOutput);
  190. formWrapper.appendChild(feedback);
  191.  
  192. container.appendChild(formWrapper);
  193.  
  194. // Finally, attach the container to document body
  195. document.body.appendChild(container);
  196. })();