授权链接添加复制按钮
Browse files- public/app.js +20 -5
public/app.js
CHANGED
|
@@ -130,7 +130,10 @@ function showOAuthModal() {
|
|
| 130 |
<p>2️⃣ 完成授权后,复制浏览器地址栏的完整URL</p>
|
| 131 |
<p>3️⃣ 粘贴URL到下方输入框并提交</p>
|
| 132 |
</div>
|
| 133 |
-
<
|
|
|
|
|
|
|
|
|
|
| 134 |
<input type="text" id="modalCallbackUrl" placeholder="粘贴完整的回调URL (http://localhost:xxxxx/oauth-callback?code=...)">
|
| 135 |
<div class="modal-actions">
|
| 136 |
<button class="btn btn-secondary" onclick="this.closest('.modal').remove()">取消</button>
|
|
@@ -164,14 +167,26 @@ function showManualModal() {
|
|
| 164 |
modal.onclick = (e) => { if (e.target === modal) modal.remove(); };
|
| 165 |
}
|
| 166 |
|
| 167 |
-
function
|
| 168 |
-
oauthPort = Math.floor(Math.random() * 10000) + 50000;
|
| 169 |
const redirectUri = `http://localhost:${oauthPort}/oauth-callback`;
|
| 170 |
-
|
| 171 |
`access_type=offline&client_id=${CLIENT_ID}&prompt=consent&` +
|
| 172 |
`redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&` +
|
| 173 |
`scope=${encodeURIComponent(SCOPES)}&state=${Date.now()}`;
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
}
|
| 176 |
|
| 177 |
async function processOAuthCallbackModal() {
|
|
|
|
| 130 |
<p>2️⃣ 完成授权后,复制浏览器地址栏的完整URL</p>
|
| 131 |
<p>3️⃣ 粘贴URL到下方输入框并提交</p>
|
| 132 |
</div>
|
| 133 |
+
<div style="display: flex; gap: 8px; margin-bottom: 16px;">
|
| 134 |
+
<button type="button" onclick="openOAuthWindow()" class="btn btn-success" style="flex: 1;">🔐 打开授权页面</button>
|
| 135 |
+
<button type="button" onclick="copyOAuthUrl()" class="btn btn-info" style="width: 44px; padding: 0; font-size: 18px;" title="复制授权链接">📋</button>
|
| 136 |
+
</div>
|
| 137 |
<input type="text" id="modalCallbackUrl" placeholder="粘贴完整的回调URL (http://localhost:xxxxx/oauth-callback?code=...)">
|
| 138 |
<div class="modal-actions">
|
| 139 |
<button class="btn btn-secondary" onclick="this.closest('.modal').remove()">取消</button>
|
|
|
|
| 167 |
modal.onclick = (e) => { if (e.target === modal) modal.remove(); };
|
| 168 |
}
|
| 169 |
|
| 170 |
+
function getOAuthUrl() {
|
| 171 |
+
if (!oauthPort) oauthPort = Math.floor(Math.random() * 10000) + 50000;
|
| 172 |
const redirectUri = `http://localhost:${oauthPort}/oauth-callback`;
|
| 173 |
+
return `https://accounts.google.com/o/oauth2/v2/auth?` +
|
| 174 |
`access_type=offline&client_id=${CLIENT_ID}&prompt=consent&` +
|
| 175 |
`redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&` +
|
| 176 |
`scope=${encodeURIComponent(SCOPES)}&state=${Date.now()}`;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
function openOAuthWindow() {
|
| 180 |
+
window.open(getOAuthUrl(), '_blank');
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function copyOAuthUrl() {
|
| 184 |
+
const url = getOAuthUrl();
|
| 185 |
+
navigator.clipboard.writeText(url).then(() => {
|
| 186 |
+
showToast('授权链接已复制到剪贴板', 'success');
|
| 187 |
+
}).catch(() => {
|
| 188 |
+
showToast('复制失败,请手动复制', 'error');
|
| 189 |
+
});
|
| 190 |
}
|
| 191 |
|
| 192 |
async function processOAuthCallbackModal() {
|