|
|
|
@ -1,10 +1,20 @@ |
|
|
|
var usernameInput = document.getElementById('username'); |
|
|
|
var passwordInput = document.getElementById('password'); |
|
|
|
|
|
|
|
// 如果已经登录,提取local中信息
|
|
|
|
chrome.storage.local.get(['loginStatus', 'loginInfo'], function(data) { |
|
|
|
if (data.loginStatus) { |
|
|
|
document.getElementById('userinfo').textContent = '已登录:' + data.loginInfo.uname; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// DOM 载入完成
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
var openIncognitoButton = document.getElementById('openIncognito'); |
|
|
|
const openIncognitoButton = document.getElementById('openIncognito'); |
|
|
|
const openLiveButton = document.getElementById('openLive'); |
|
|
|
const loginButton = document.getElementById('login'); |
|
|
|
|
|
|
|
// 打开抖音
|
|
|
|
openIncognitoButton.addEventListener('click', function() { |
|
|
|
const username = usernameInput.value; |
|
|
|
const password = passwordInput.value; |
|
|
|
@ -17,8 +27,7 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
}, function(response) { |
|
|
|
if (response && response.success) { |
|
|
|
console.log('隐身窗口已打开,准备提交登录'); |
|
|
|
// 这里可以添加提交登录的逻辑
|
|
|
|
// 例如:向新打开的窗口发送消息,执行登录操作
|
|
|
|
// 向新打开的窗口发送消息,执行登录操作
|
|
|
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { |
|
|
|
chrome.tabs.sendMessage(tabs[0].id, { |
|
|
|
action: 'submitLogin', |
|
|
|
@ -32,7 +41,8 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
document.getElementById('openLive').addEventListener('click', () => { |
|
|
|
// 打开直播间
|
|
|
|
openLiveButton.addEventListener('click', () => { |
|
|
|
const liveId = document.getElementById('liveId').value; |
|
|
|
if (liveId) { |
|
|
|
const liveUrl = `https://live.douyin.com/${liveId}`; |
|
|
|
@ -40,12 +50,7 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//登录按钮
|
|
|
|
const loginButton = document.getElementById('login'); |
|
|
|
// const loginTimeInput = document.getElementById('loginTime');
|
|
|
|
// const loginTime = loginTimeInput.value;
|
|
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
loginButton.addEventListener('click', function() { |
|
|
|
const username = usernameInput.value; |
|
|
|
const password = passwordInput.value; |
|
|
|
@ -53,48 +58,20 @@ document.addEventListener('DOMContentLoaded', function() { |
|
|
|
if (!username || !password) { |
|
|
|
alert('请输入账号和密码!'); |
|
|
|
return; |
|
|
|
}else{ |
|
|
|
performLogin(username, password); |
|
|
|
} else { |
|
|
|
// 发送到后台打开
|
|
|
|
chrome.runtime.sendMessage({ action: 'login', username: username, password: password }); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function performLogin(username, password) { |
|
|
|
console.log(`正在执行登录,用户名:${username}`); |
|
|
|
|
|
|
|
const loginData = { |
|
|
|
uname: username, |
|
|
|
upass: password |
|
|
|
}; |
|
|
|
|
|
|
|
fetch('https://douyin.xingtongworld.com/api/passport/login?t=crx', { |
|
|
|
method: 'POST', |
|
|
|
headers: { |
|
|
|
'Content-Type': 'application/json', |
|
|
|
'Accept': 'application/json' |
|
|
|
}, |
|
|
|
body: JSON.stringify(loginData) |
|
|
|
}) |
|
|
|
.then(response => { |
|
|
|
console.log('Response status:', response.status); |
|
|
|
if (!response.ok) { |
|
|
|
throw new Error(`HTTP error! status: ${response.status}`); |
|
|
|
} |
|
|
|
return response.json(); |
|
|
|
}) |
|
|
|
.then(data => { |
|
|
|
console.log('登录结果:', data); |
|
|
|
if (data.status === 200) { |
|
|
|
alert('登录成功!'); |
|
|
|
// 这里可以添加登录成功后的操作
|
|
|
|
// 监听登录结果
|
|
|
|
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { |
|
|
|
if (request.action === 'loginResult') { |
|
|
|
if (request.status === 'success') { |
|
|
|
document.getElementById('userinfo').textContent = '已登录:' + request.uname; |
|
|
|
} else { |
|
|
|
alert('登录失败:' + (data.message || '未知错误')); |
|
|
|
alert('登录失败:' + request.message); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
console.error('登录请求出错:', error); |
|
|
|
alert('登录请求出错,请检查网络连接或稍后重试。'); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|