feat: add browser extension origin save
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
2. 点击“生成导入码”,复制 SmartUp 地址和导入码。
|
||||
3. 在本机真实浏览器打开 Meow/New-API 页面并完成登录。
|
||||
4. 点击 SmartUp Auth Importer 扩展图标。
|
||||
5. 粘贴 SmartUp 地址和导入码。
|
||||
5. 粘贴 SmartUp 地址和导入码;如果 SmartUp 部署在远程服务器,可以先点击“保存地址”长期复用该地址。
|
||||
6. 点击“采集当前页并回填”。
|
||||
7. 回到 SmartUp,等待候选凭证出现后点击“填入当前表单”。
|
||||
|
||||
|
||||
@@ -29,6 +29,14 @@
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.origin-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.origin-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
button {
|
||||
width: 100%;
|
||||
margin-top: 12px;
|
||||
@@ -40,6 +48,14 @@
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.origin-row button {
|
||||
width: auto;
|
||||
margin-top: 0;
|
||||
padding: 8px 10px;
|
||||
white-space: nowrap;
|
||||
background: #374151;
|
||||
font-size: 12px;
|
||||
}
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
@@ -64,7 +80,10 @@
|
||||
<body>
|
||||
<h1>SmartUp 凭证导入</h1>
|
||||
<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>
|
||||
<input id="code" placeholder="session_id:secret" />
|
||||
<div class="hint">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const smartupInput = document.getElementById('smartup')
|
||||
const codeInput = document.getElementById('code')
|
||||
const submitButton = document.getElementById('submit')
|
||||
const saveOriginButton = document.getElementById('save-origin')
|
||||
const statusEl = document.getElementById('status')
|
||||
|
||||
function setStatus(text, cls = '') {
|
||||
@@ -33,6 +34,25 @@ async function saveConfig(origin, 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() {
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true })
|
||||
if (!tab?.id || !tab.url || !/^https?:\/\//.test(tab.url)) {
|
||||
@@ -135,4 +155,8 @@ submitButton.addEventListener('click', () => {
|
||||
void submitImport()
|
||||
})
|
||||
|
||||
saveOriginButton.addEventListener('click', () => {
|
||||
void saveOriginOnly()
|
||||
})
|
||||
|
||||
void loadSavedConfig()
|
||||
|
||||
Reference in New Issue
Block a user