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.
72 lines
2.3 KiB
72 lines
2.3 KiB
console.log('抖音扩展背景脚本已加载');
|
|
|
|
chrome.runtime.onInstalled.addListener(() => {
|
|
console.log("抖音扩展已安装");
|
|
});
|
|
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.action === 'openIncognitoDouyin') {
|
|
chrome.windows.create({
|
|
incognito: true,
|
|
url: "https://www.douyin.com"
|
|
}, function(window) {
|
|
console.log('抖音隐身窗口已打开');
|
|
// 这里可以添加自动登录的逻辑
|
|
});
|
|
} else if (request.action === 'openLiveIncognito') {
|
|
chrome.windows.create({
|
|
incognito: true,
|
|
url: request.url
|
|
}, function(window) {
|
|
console.log('直播隐身窗口已打开');
|
|
});
|
|
}
|
|
|
|
//执行登录
|
|
if (request.action === 'login') {
|
|
console.log('收到登录请求');
|
|
// 登录数据
|
|
const loginData = {
|
|
uname: request.username,
|
|
upass: request.password
|
|
};
|
|
// 在这里处理登录逻辑
|
|
fetch('https://douyin.xingtongworld.com/api/passport/login?t=crx', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(loginData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
console.log('登录结果:', data);
|
|
if (data.status === 200) {
|
|
|
|
// 这里可以添加登录成功后的操作
|
|
sendResponse({ status: 'success' });
|
|
// 保存登录状态
|
|
chrome.storage.local.set({ loginStatus: true });
|
|
// 保存登录信息
|
|
chrome.storage.local.set({ loginInfo: loginData });
|
|
// 保存登录时间
|
|
chrome.storage.local.set({ loginTime: new Date().toLocaleString() });
|
|
// 保存登录token
|
|
chrome.storage.local.set({ loginToken: data.token });
|
|
// 保存登录cookie
|
|
chrome.cookies.set({
|
|
url: 'https://douyin.xingtongworld.com',
|
|
name: 'sessionid',
|
|
value: data.token,
|
|
domain: 'douyin.xingtongworld.com'
|
|
});
|
|
} else {
|
|
sendResponse({ status: 'error', message: '登录失败:' + (data.message || '未知错误') });
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('登录请求出错:', error);
|
|
sendResponse({ status: 'error', message: '登录请求出错,请检查网络连接或稍后重试。' });
|
|
});
|
|
}
|
|
});
|