diff --git a/douyin/popup.html b/douyin/popup.html index 1c50e2b..a35ec76 100644 --- a/douyin/popup.html +++ b/douyin/popup.html @@ -27,6 +27,8 @@ + + diff --git a/douyin/popup.js b/douyin/popup.js index 2089189..5887a6e 100644 --- a/douyin/popup.js +++ b/douyin/popup.js @@ -1,16 +1,34 @@ +var usernameInput = document.getElementById('username'); +var passwordInput = document.getElementById('password'); + +// DOM 载入完成 document.addEventListener('DOMContentLoaded', function() { var openIncognitoButton = document.getElementById('openIncognito'); - var usernameInput = document.getElementById('username'); - var passwordInput = document.getElementById('password'); 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('打开隐身窗口失败'); + } }); }); @@ -21,4 +39,74 @@ document.addEventListener('DOMContentLoaded', function() { chrome.runtime.sendMessage({ action: 'openLiveIncognito', url: liveUrl }); } }); + + //登录按钮 + 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; + + if (!username || !password) { + alert('请输入账号和密码!'); + return; + }else{ + performLogin(username, password); + } + // performLogin(username, password); + + // if (!loginTime) { + // // 如果没有设置登录时间,立即执行登录 + // performLogin(username, password); + // } else { + // // 如果设置了登录时间,计算延迟并设置定时器 + // const now = new Date(); + // const loginDateTime = new Date(now.toDateString() + ' ' + loginTime); + // const delay = loginDateTime.getTime() - now.getTime(); + + // if (delay < 0) { + // alert('登录时间已过,请重新设置!'); + // return; + // } + + // alert(`登录将在 ${loginTime} 进行,请保持浏览器打开。`); + // setTimeout(() => performLogin(username, password), delay); + // } + }); + + function performLogin(username, password) { + console.log(`正在执行登录,用户名:${username}`); + + // 创建要发送的数据对象 + const loginData = { + username: username, + password: password + }; + + // 使用 fetch API 发送 POST 请求 + fetch('https://douyin.xingtongworld.com/api/passport/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(loginData) + }) + .then(response => response.json()) + .then(data => { + console.log('登录结果:', data); + if (data.status === 200) { + alert('登录成功!'); + // 这里可以添加登录成功后的操作 + } else { + alert('登录失败:' + data.message); + } + }) + .catch(error => { + console.error('登录请求出错:', error); + alert('登录请求出错,请检查网络连接或稍后重试。'); + }); + } }); \ No newline at end of file