doufire 前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
2.5 KiB

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() {
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;
// 发送消息到后台脚本以打开隐身窗口
chrome.runtime.sendMessage({
action: 'openIncognitoDouyin',
username: username,
password: password
}, 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',
username: username,
password: password
});
});
} else {
console.error('打开隐身窗口失败');
}
});
});
// 打开直播间
openLiveButton.addEventListener('click', () => {
const liveId = document.getElementById('liveId').value;
if (liveId) {
const liveUrl = `https://live.douyin.com/${liveId}`;
chrome.runtime.sendMessage({ action: 'openLiveIncognito', url: liveUrl });
}
});
// 登录
loginButton.addEventListener('click', function() {
const username = usernameInput.value;
const password = passwordInput.value;
if (!username || !password) {
alert('请输入账号和密码!');
return;
} else {
// 发送到后台打开
chrome.runtime.sendMessage({ action: 'login', username: username, password: password });
}
});
// 监听登录结果
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === 'loginResult') {
if (request.status === 'success') {
document.getElementById('userinfo').textContent = '已登录:' + request.uname;
} else {
alert('登录失败:' + request.message);
}
}
});
});