Pārlūkot izejas kodu

feat(email-generator): 更新 Cloudflare 邮箱生成逻辑,使用 10 位随机前缀格式

QLHazyCoder 4 mēneši atpakaļ
vecāks
revīzija
fbaf7629b8
2 mainītis faili ar 22 papildinājumiem un 14 dzēšanām
  1. 4 3
      README.md
  2. 18 11
      background.js

+ 4 - 3
README.md

@@ -182,9 +182,10 @@ Cloudflare 模式下,插件不会再调用 Cloudflare API 创建路由。
 它现在只做一件事:
 
 1. 根据你当前选中的 `CF 域名`
-2. 本地生成一个随机前缀
-3. 直接得到一个类似 `user20260412153000123@example.xyz` 的注册邮箱
-4. 把这个邮箱写入当前流程继续往下跑
+2. 本地生成一个 10 位随机前缀
+3. 前缀由 `6 个小写字母 + 4 个数字` 组成,顺序随机打乱
+4. 直接得到一个类似 `a3b9cd1e2f@example.xyz` 的注册邮箱
+5. 把这个邮箱写入当前流程继续往下跑
 
 也就是说,插件默认认为:
 

+ 18 - 11
background.js

@@ -3027,17 +3027,24 @@ function getEmailGeneratorLabel(generator) {
 }
 
 function generateCloudflareAliasLocalPart() {
-  const now = new Date();
-  const stamp = [
-    now.getFullYear(),
-    String(now.getMonth() + 1).padStart(2, '0'),
-    String(now.getDate()).padStart(2, '0'),
-    String(now.getHours()).padStart(2, '0'),
-    String(now.getMinutes()).padStart(2, '0'),
-    String(now.getSeconds()).padStart(2, '0'),
-  ].join('');
-  const randomPart = String(Math.floor(Math.random() * 900) + 100);
-  return `user${stamp}${randomPart}`.toLowerCase();
+  const letters = 'abcdefghijklmnopqrstuvwxyz';
+  const digits = '0123456789';
+  const chars = [];
+
+  for (let i = 0; i < 6; i++) {
+    chars.push(letters[Math.floor(Math.random() * letters.length)]);
+  }
+
+  for (let i = 0; i < 4; i++) {
+    chars.push(digits[Math.floor(Math.random() * digits.length)]);
+  }
+
+  for (let i = chars.length - 1; i > 0; i--) {
+    const j = Math.floor(Math.random() * (i + 1));
+    [chars[i], chars[j]] = [chars[j], chars[i]];
+  }
+
+  return chars.join('');
 }
 
 async function fetchCloudflareEmail(state, options = {}) {