Browse Source

1111

torsen
TorsenLi 1 year ago
parent
commit
fe73e5aa36
  1. 8
      douyin/background.js
  2. 94
      douyin/popup.js

8
douyin/background.js

@ -69,4 +69,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
sendResponse({ status: 'error', message: '登录请求出错,请检查网络连接或稍后重试。' });
});
}
// 添加状态检查功能
if (request.action === 'checkStatus') {
// 执行状态检查的逻辑
// 这里只是一个示例,您需要根据实际需求实现检查逻辑
let status = '正常';
sendResponse({status: status});
}
});

94
douyin/popup.js

@ -1,25 +1,41 @@
var usernameInput = document.getElementById('username');
var passwordInput = document.getElementById('password');
// 将所有的 DOM 操作移到 DOMContentLoaded 事件监听器内部
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM 已加载完成');
var usernameInput = document.getElementById('username');
var passwordInput = document.getElementById('password');
var liveIdInput = document.getElementById('liveId');
const openIncognitoButton = document.getElementById('openIncognito');
const openLiveButton = document.getElementById('openLive');
const loginButton = document.getElementById('login');
const checkButton = document.getElementById('checkButton');
const userinfoElement = document.getElementById('userinfo');
console.log('元素检查:',
'usernameInput:', !!usernameInput,
'passwordInput:', !!passwordInput,
'liveIdInput:', !!liveIdInput,
'openIncognitoButton:', !!openIncognitoButton,
'openLiveButton:', !!openLiveButton,
'loginButton:', !!loginButton,
'checkButton:', !!checkButton,
'userinfoElement:', !!userinfoElement
);
// 如果已经登录,提取local中信息
chrome.storage.local.get(['loginStatus', 'loginInfo'], function(data) {
if (data.loginStatus) {
document.getElementById('userinfo').textContent = '已登录:' + data.loginInfo.uname;
if (data.loginStatus && userinfoElement) {
userinfoElement.textContent = '已登录:' + data.loginInfo.uname;
}
});
// DOM 载入完成
document.addEventListener('DOMContentLoaded', function() {
const openIncognitoButton = document.getElementById('openIncognito');
const openLiveButton = document.getElementById('openLive');
const loginButton = document.getElementById('login');
// 打开抖音
if (openIncognitoButton) {
openIncognitoButton.addEventListener('click', function() {
const username = usernameInput.value;
const password = passwordInput.value;
console.log('打开隐身窗口按钮被点击');
const username = usernameInput ? usernameInput.value : '';
const password = passwordInput ? passwordInput.value : '';
// 发送消息到后台脚本以打开隐身窗口
chrome.runtime.sendMessage({
action: 'openIncognitoDouyin',
username: username,
@ -27,7 +43,6 @@ 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',
@ -40,38 +55,69 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
});
} else {
console.error('未找到打开隐身窗口按钮');
}
// 打开直播间
if (openLiveButton && liveIdInput) {
openLiveButton.addEventListener('click', () => {
const liveId = document.getElementById('liveId').value;
console.log('打开直播间按钮被点击');
const liveId = liveIdInput.value.trim();
if (liveId) {
const liveUrl = `https://live.douyin.com/${liveId}`;
chrome.runtime.sendMessage({ action: 'openLiveIncognito', url: liveUrl });
} else {
console.error('未输入直播ID');
alert('请输入直播ID');
}
});
} else {
console.error('未找到打开直播间按钮或直播ID输入框');
}
// 登录
if (loginButton && usernameInput && passwordInput) {
loginButton.addEventListener('click', function() {
const username = usernameInput.value;
const password = passwordInput.value;
console.log('登录按钮被点击');
const username = usernameInput.value.trim();
const password = passwordInput.value.trim();
if (!username || !password) {
alert('请输入账号和密码!');
return;
} else {
// 发送到后台打开
chrome.runtime.sendMessage({ action: 'login', username: username, password: password });
}
});
} else {
console.error('未找到登录按钮或用户名/密码输入框');
}
// 监听登录结果
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
// 添加新的检查按钮功能
if (checkButton) {
checkButton.addEventListener('click', function() {
console.log('检查状态按钮被点击');
chrome.runtime.sendMessage({action: 'checkStatus'}, function(response) {
console.log('状态检查结果:', response);
alert('状态检查结果: ' + (response && response.status ? response.status : '未知'));
});
});
} else {
console.error('未找到检查状态按钮');
}
});
// 监听登录结果
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === 'loginResult') {
if (request.status === 'success') {
document.getElementById('userinfo').textContent = '已登录:' + request.uname;
const userinfoElement = document.getElementById('userinfo');
if (request.status === 'success' && userinfoElement) {
userinfoElement.textContent = '已登录:' + request.uname;
} else {
alert('登录失败:' + request.message);
alert('登录失败:' + (request.message || '未知错误'));
}
}
});
});
console.log('popup.js 脚本已加载完成');

Loading…
Cancel
Save