chrome_extensions/js/background.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

/*
* @Author: lingling 1077478963@qq.com
* @Date: 2024-08-19 09:47:04
* @LastEditors: lingling 1077478963@qq.com
* @LastEditTime: 2024-09-27 15:57:31
* @FilePath: \谷歌自动搜索邮箱自动点击v3\js\background.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
2024-09-24 17:52:21 +08:00
//记录谷歌账户
let Ggoogle_mail = "";
2024-09-24 17:52:21 +08:00
//记录是否有运行权限
let executionAuthority = false;
2024-09-24 17:52:21 +08:00
//是否查询过
let haveYouChecked = false;
2024-09-24 17:52:21 +08:00
/**
* 查看是否有权限运行
* @param {*} google_mail 谷歌id
*/
2024-09-25 14:54:52 +08:00
//TODO 授权没写完
async function viewPermission(google_mail) {
let tmp = await axios.post(
"http://149.129.107.38:8787/index/queryauthorization",
{ google_account: google_mail }
);
if (tmp.data.code == 200) {
executionAuthority = true;
Ggoogle_mail = google_mail;
2024-09-24 17:52:21 +08:00
return true;
}
haveYouChecked = true;
return false;
2024-09-24 17:52:21 +08:00
}
/**
* 监听消息
* @param {*} req 发送过来的消息
* @param {*} sendResponse 返回消息
*/
chrome.runtime.onMessage.addListener(async (req, sender, sendResponse) => {
if (haveYouChecked) {
sendResponse(executionAuthority);
return true;
}
if (req.ty == "viewPermission") {
const res = req.info;
if (res&&!haveYouChecked) {
let data = await viewPermission(res);
console.log(data);
sendResponse(data);
2024-09-25 14:54:52 +08:00
}
}
return true;
});
2024-09-24 17:52:21 +08:00
setTimeout(function () {
chrome.tabs.create({ url: "popup.html" }, function () {});
}, 3500);