|
|
@@ -50,7 +50,7 @@ const onFirstMount = async() => {
|
|
|
webTokenWrapper.style.marginTop = '20px';
|
|
|
webTokenWrapper.style.marginBottom = '20px';
|
|
|
webTokenWrapper.style.width = '100%';
|
|
|
- webTokenWrapper.style.maxWidth = '320px';
|
|
|
+ webTokenWrapper.style.maxWidth = '400px';
|
|
|
webTokenWrapper.style.margin = '20px auto';
|
|
|
|
|
|
const webTokenTitle = document.createElement('div');
|
|
|
@@ -64,7 +64,6 @@ const onFirstMount = async() => {
|
|
|
|
|
|
const tokenInput = document.createElement('textarea');
|
|
|
tokenInput.classList.add('input-field');
|
|
|
- tokenInput.placeholder = '';
|
|
|
tokenInput.style.width = '100%';
|
|
|
tokenInput.style.padding = '12px';
|
|
|
tokenInput.style.borderRadius = '8px';
|
|
|
@@ -75,39 +74,51 @@ const onFirstMount = async() => {
|
|
|
tokenInput.style.fontFamily = 'inherit';
|
|
|
tokenInput.rows = 8;
|
|
|
|
|
|
- // 按钮容器
|
|
|
+ // 按钮容器 - 三个按钮一排,两个登录按钮在左边
|
|
|
const buttonContainer = document.createElement('div');
|
|
|
buttonContainer.style.display = 'flex';
|
|
|
- buttonContainer.style.gap = '5px';
|
|
|
- buttonContainer.style.justifyContent = 'space-between';
|
|
|
+ buttonContainer.style.gap = '8px';
|
|
|
buttonContainer.style.width = '100%';
|
|
|
buttonContainer.style.marginTop = '10px';
|
|
|
|
|
|
- // 登录按钮
|
|
|
+ // Token登录按钮
|
|
|
const tokenBtn = document.createElement('button');
|
|
|
- tokenBtn.textContent = '使用Token登录';
|
|
|
- tokenBtn.style.flex = '1';
|
|
|
- tokenBtn.style.maxWidth = 'calc(50% - 5px)';
|
|
|
- tokenBtn.style.backgroundColor = 'transparent';
|
|
|
- tokenBtn.style.color = 'var(--primary-color)';
|
|
|
+ tokenBtn.textContent = 'Token登录';
|
|
|
+ tokenBtn.style.flex = '0 0 auto';
|
|
|
+ tokenBtn.style.backgroundColor = 'var(--primary-color)';
|
|
|
+ tokenBtn.style.color = 'white';
|
|
|
tokenBtn.style.border = 'none';
|
|
|
tokenBtn.style.padding = '10px 15px';
|
|
|
tokenBtn.style.cursor = 'pointer';
|
|
|
tokenBtn.style.fontWeight = '500';
|
|
|
tokenBtn.style.fontSize = '14px';
|
|
|
+ tokenBtn.style.borderRadius = '6px';
|
|
|
+
|
|
|
+ // Session登录按钮
|
|
|
+ const sessionBtn = document.createElement('button');
|
|
|
+ sessionBtn.textContent = 'Session登录';
|
|
|
+ sessionBtn.style.flex = '0 0 auto';
|
|
|
+ sessionBtn.style.backgroundColor = 'var(--primary-color)';
|
|
|
+ sessionBtn.style.color = 'white';
|
|
|
+ sessionBtn.style.border = 'none';
|
|
|
+ sessionBtn.style.padding = '10px 15px';
|
|
|
+ sessionBtn.style.cursor = 'pointer';
|
|
|
+ sessionBtn.style.fontWeight = '500';
|
|
|
+ sessionBtn.style.fontSize = '14px';
|
|
|
+ sessionBtn.style.borderRadius = '6px';
|
|
|
|
|
|
// 导出按钮
|
|
|
const exportBtn = document.createElement('button');
|
|
|
exportBtn.textContent = '导出聊天记录';
|
|
|
exportBtn.style.flex = '1';
|
|
|
- exportBtn.style.maxWidth = 'calc(50% - 5px)';
|
|
|
- exportBtn.style.backgroundColor = 'transparent';
|
|
|
- exportBtn.style.color = 'var(--primary-color)';
|
|
|
+ exportBtn.style.backgroundColor = 'var(--primary-color)';
|
|
|
+ exportBtn.style.color = 'white';
|
|
|
exportBtn.style.border = 'none';
|
|
|
exportBtn.style.padding = '10px 15px';
|
|
|
exportBtn.style.cursor = 'pointer';
|
|
|
exportBtn.style.fontWeight = '500';
|
|
|
exportBtn.style.fontSize = '14px';
|
|
|
+ exportBtn.style.borderRadius = '6px';
|
|
|
|
|
|
// 不需要任何点击效果
|
|
|
|
|
|
@@ -239,13 +250,108 @@ const onFirstMount = async() => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 添加按钮到容器
|
|
|
- buttonContainer.append(tokenBtn, exportBtn);
|
|
|
+ // 添加三个按钮到容器 - 两个登录按钮在左边
|
|
|
+ buttonContainer.append(tokenBtn, sessionBtn, exportBtn);
|
|
|
|
|
|
// 组合元素
|
|
|
tokenInputContainer.append(tokenInput, buttonContainer);
|
|
|
webTokenWrapper.append(webTokenTitle, tokenInputContainer);
|
|
|
|
|
|
+ // 添加分隔线
|
|
|
+ const divider = document.createElement('div');
|
|
|
+ divider.style.cssText = 'width: 100%; height: 1px; background: var(--border-color); margin: 20px 0;';
|
|
|
+
|
|
|
+ // Session错误提示
|
|
|
+ const sessionError = document.createElement('div');
|
|
|
+ sessionError.classList.add('session-error');
|
|
|
+ sessionError.style.color = 'var(--danger-color)';
|
|
|
+ sessionError.style.fontSize = '14px';
|
|
|
+ sessionError.style.marginTop = '5px';
|
|
|
+ sessionError.style.display = 'none';
|
|
|
+ sessionError.style.textAlign = 'center';
|
|
|
+
|
|
|
+ // Session数据注入按钮点击事件
|
|
|
+ sessionBtn.addEventListener('click', async() => {
|
|
|
+ const sessionData = tokenInput.value.trim();
|
|
|
+ if(!sessionData) {
|
|
|
+ toast('请输入Session数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 尝试解析Base64数据
|
|
|
+ let parsedData;
|
|
|
+ try {
|
|
|
+ const decodedString = atob(sessionData);
|
|
|
+ parsedData = JSON.parse(decodedString);
|
|
|
+ } catch(e) {
|
|
|
+ // 如果不是Base64,尝试直接解析JSON
|
|
|
+ try {
|
|
|
+ parsedData = JSON.parse(sessionData);
|
|
|
+ } catch(e2) {
|
|
|
+ throw new Error('数据格式无效,请确保输入正确的Base64编码或JSON数据');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证数据格式
|
|
|
+ if(!parsedData || typeof parsedData !== 'object') {
|
|
|
+ throw new Error('数据格式无效');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找登录相关的数据
|
|
|
+ const loginKeys = ['dc', 'dcId', 'serverTimeOffset', 'auth_key', 'user_id', 'userId', 'session'];
|
|
|
+ const foundLoginData: any = {};
|
|
|
+ for(const key of loginKeys) {
|
|
|
+ if(parsedData[key] !== undefined) {
|
|
|
+ foundLoginData[key] = parsedData[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有足够的登录数据
|
|
|
+ if(Object.keys(foundLoginData).length === 0) {
|
|
|
+ throw new Error('未找到有效的登录数据,请确保数据包含dc、auth_key等信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示找到的登录数据
|
|
|
+ console.log('找到的登录数据:', foundLoginData);
|
|
|
+ toast('正在注入Session数据到localStorage...');
|
|
|
+
|
|
|
+ // 将解析后的数据重新注入到localStorage中
|
|
|
+ let injectedCount = 0;
|
|
|
+ for(const [key, value] of Object.entries(parsedData)) {
|
|
|
+ try {
|
|
|
+ localStorage.setItem(key, value as string);
|
|
|
+ injectedCount++;
|
|
|
+ } catch(e) {
|
|
|
+ console.warn(`无法注入键 ${key}:`, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ toast(`Session数据注入成功!共注入 ${injectedCount} 个键值对`);
|
|
|
+
|
|
|
+ // 自动刷新页面以应用新的localStorage数据
|
|
|
+ setTimeout(() => {
|
|
|
+ window.location.reload();
|
|
|
+ }, 1500);
|
|
|
+ } catch(error) {
|
|
|
+ console.error('Session数据注入失败:', error);
|
|
|
+ sessionError.textContent = (error as Error).message || 'Session数据注入失败';
|
|
|
+ sessionError.style.display = 'block';
|
|
|
+
|
|
|
+ // 3秒后隐藏错误信息
|
|
|
+ setTimeout(() => {
|
|
|
+ sessionError.style.display = 'none';
|
|
|
+ }, 3000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 按下Enter键也可以提交
|
|
|
+ tokenInput.addEventListener('keypress', (e) => {
|
|
|
+ if(e.key === 'Enter' && !sessionBtn.disabled) {
|
|
|
+ sessionBtn.click();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
const container = imageDiv.parentElement;
|
|
|
|
|
|
/*
|