feat: add browser extension origin save

This commit is contained in:
liumangmang
2026-06-02 15:32:43 +08:00
parent 84148f4a69
commit 3181a6f6cc
3 changed files with 45 additions and 2 deletions
+1 -1
View File
@@ -15,7 +15,7 @@
2. 点击“生成导入码”,复制 SmartUp 地址和导入码。 2. 点击“生成导入码”,复制 SmartUp 地址和导入码。
3. 在本机真实浏览器打开 Meow/New-API 页面并完成登录。 3. 在本机真实浏览器打开 Meow/New-API 页面并完成登录。
4. 点击 SmartUp Auth Importer 扩展图标。 4. 点击 SmartUp Auth Importer 扩展图标。
5. 粘贴 SmartUp 地址和导入码。 5. 粘贴 SmartUp 地址和导入码;如果 SmartUp 部署在远程服务器,可以先点击“保存地址”长期复用该地址
6. 点击“采集当前页并回填”。 6. 点击“采集当前页并回填”。
7. 回到 SmartUp,等待候选凭证出现后点击“填入当前表单”。 7. 回到 SmartUp,等待候选凭证出现后点击“填入当前表单”。
+20 -1
View File
@@ -29,6 +29,14 @@
border-radius: 6px; border-radius: 6px;
font-size: 13px; font-size: 13px;
} }
.origin-row {
display: flex;
gap: 8px;
}
.origin-row input {
flex: 1;
min-width: 0;
}
button { button {
width: 100%; width: 100%;
margin-top: 12px; margin-top: 12px;
@@ -40,6 +48,14 @@
font-weight: 600; font-weight: 600;
cursor: pointer; cursor: pointer;
} }
.origin-row button {
width: auto;
margin-top: 0;
padding: 8px 10px;
white-space: nowrap;
background: #374151;
font-size: 12px;
}
button:disabled { button:disabled {
opacity: 0.6; opacity: 0.6;
cursor: not-allowed; cursor: not-allowed;
@@ -64,7 +80,10 @@
<body> <body>
<h1>SmartUp 凭证导入</h1> <h1>SmartUp 凭证导入</h1>
<label for="smartup">SmartUp 地址</label> <label for="smartup">SmartUp 地址</label>
<input id="smartup" placeholder="http://127.0.0.1:8899" /> <div class="origin-row">
<input id="smartup" placeholder="http://127.0.0.1:8899" />
<button id="save-origin" type="button">保存地址</button>
</div>
<label for="code">导入码</label> <label for="code">导入码</label>
<input id="code" placeholder="session_id:secret" /> <input id="code" placeholder="session_id:secret" />
<div class="hint"> <div class="hint">
+24
View File
@@ -1,6 +1,7 @@
const smartupInput = document.getElementById('smartup') const smartupInput = document.getElementById('smartup')
const codeInput = document.getElementById('code') const codeInput = document.getElementById('code')
const submitButton = document.getElementById('submit') const submitButton = document.getElementById('submit')
const saveOriginButton = document.getElementById('save-origin')
const statusEl = document.getElementById('status') const statusEl = document.getElementById('status')
function setStatus(text, cls = '') { function setStatus(text, cls = '') {
@@ -33,6 +34,25 @@ async function saveConfig(origin, code) {
await chrome.storage.local.set({ smartupOrigin: origin, importCode: code }) await chrome.storage.local.set({ smartupOrigin: origin, importCode: code })
} }
async function saveOriginOnly() {
const smartupOrigin = normalizeOrigin(smartupInput.value)
if (!smartupOrigin) {
setStatus('SmartUp 地址必须以 http:// 或 https:// 开头', 'err')
return
}
saveOriginButton.disabled = true
try {
await chrome.storage.local.set({ smartupOrigin })
smartupInput.value = smartupOrigin
setStatus('SmartUp 地址已保存', 'ok')
} catch (error) {
setStatus(error?.message || '保存失败', 'err')
} finally {
saveOriginButton.disabled = false
}
}
async function getActiveTab() { async function getActiveTab() {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) const [tab] = await chrome.tabs.query({ active: true, currentWindow: true })
if (!tab?.id || !tab.url || !/^https?:\/\//.test(tab.url)) { if (!tab?.id || !tab.url || !/^https?:\/\//.test(tab.url)) {
@@ -135,4 +155,8 @@ submitButton.addEventListener('click', () => {
void submitImport() void submitImport()
}) })
saveOriginButton.addEventListener('click', () => {
void saveOriginOnly()
})
void loadSavedConfig() void loadSavedConfig()