修改viewPermission all函数
This commit is contained in:
parent
7a67c00bee
commit
d57fe2b04d
|
@ -2,7 +2,7 @@
|
|||
* @Author: lingling 1077478963@qq.com
|
||||
* @Date: 2024-08-19 09:47:04
|
||||
* @LastEditors: lingling 1077478963@qq.com
|
||||
* @LastEditTime: 2024-09-27 15:57:31
|
||||
* @LastEditTime: 2024-09-29 14:41:33
|
||||
* @FilePath: \谷歌自动搜索邮箱自动点击v3\js\background.js
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
|
@ -12,12 +12,13 @@ let Ggoogle_mail = "";
|
|||
let executionAuthority = false;
|
||||
//是否查询过
|
||||
let haveYouChecked = false;
|
||||
|
||||
/**
|
||||
* 查看是否有权限运行
|
||||
* @param {*} google_mail 谷歌id
|
||||
*/
|
||||
//TODO 授权没写完
|
||||
async function viewPermission(google_mail) {
|
||||
try {
|
||||
let tmp = await axios.post(
|
||||
"http://149.129.107.38:8787/index/queryauthorization",
|
||||
{ google_account: google_mail }
|
||||
|
@ -27,31 +28,39 @@ async function viewPermission(google_mail) {
|
|||
Ggoogle_mail = google_mail;
|
||||
return true;
|
||||
}
|
||||
haveYouChecked = true;
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error("Error fetching permission:", error);
|
||||
return false;
|
||||
} finally {
|
||||
haveYouChecked = true; // 保证状态更新,即使出现错误
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听消息
|
||||
* @param {*} req 发送过来的消息
|
||||
* @param {*} sendResponse 返回消息
|
||||
*/
|
||||
chrome.runtime.onMessage.addListener(async (req, sender, sendResponse) => {
|
||||
if (req.ty === "viewPermission") {
|
||||
if (haveYouChecked) {
|
||||
// 如果已经查询过,直接返回权限状态
|
||||
sendResponse(executionAuthority);
|
||||
return true;
|
||||
}
|
||||
if (req.ty == "viewPermission") {
|
||||
} else {
|
||||
// 没有查询过,执行异步查询
|
||||
const res = req.info;
|
||||
if (res&&!haveYouChecked) {
|
||||
let data = await viewPermission(res);
|
||||
console.log(data);
|
||||
sendResponse(data);
|
||||
const data = await viewPermission(res);
|
||||
// const data = true;
|
||||
sendResponse(data); // 异步响应结果
|
||||
}
|
||||
return true; // 保持消息通道开放,等待异步 sendResponse
|
||||
}
|
||||
return true;
|
||||
// 其他消息类型的处理
|
||||
return false; // 关闭通道,表示没有需要处理的异步操作
|
||||
});
|
||||
|
||||
// 启动扩展时自动创建一个新标签页
|
||||
setTimeout(function () {
|
||||
chrome.tabs.create({ url: "popup.html" }, function () {});
|
||||
chrome.tabs.create({ url: "popup.html" });
|
||||
}, 3500);
|
||||
|
|
39
js/popup.js
39
js/popup.js
|
@ -2,11 +2,16 @@
|
|||
* @Author: lingling 1077478963@qq.com
|
||||
* @Date: 2024-08-19 09:47:04
|
||||
* @LastEditors: lingling 1077478963@qq.com
|
||||
* @LastEditTime: 2024-09-27 16:04:40
|
||||
* @LastEditTime: 2024-09-29 14:07:35
|
||||
* @FilePath: \谷歌自动搜索邮箱自动点击v3\js\popup.js
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
$(function () {
|
||||
/**
|
||||
* 数组打乱随机执行
|
||||
* @param {*} array
|
||||
* @returns
|
||||
*/
|
||||
function shuffleArray(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
|
@ -51,16 +56,20 @@ $(function () {
|
|||
sender,
|
||||
sendResponse
|
||||
) {
|
||||
console.log(request)
|
||||
// 判断是产生一个新页面是
|
||||
if (request.ty == "get") {
|
||||
sendResponse({ name, id });
|
||||
}
|
||||
if (request.ty == "remove") {
|
||||
|
||||
chrome.tabs.remove(id);
|
||||
chrome.tabs.remove(sender.tab.id);
|
||||
}
|
||||
if(request.ty == "get"||request.ty == "remove"){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
async function google() {
|
||||
|
@ -112,11 +121,7 @@ $(function () {
|
|||
// queue.push(youtube);
|
||||
// queue.push(play_google);
|
||||
// queue.push(youtube_shorts);
|
||||
queue.push(news_google);
|
||||
|
||||
//乱序执行 此处有问题
|
||||
// queue=shuffleArray(queue)
|
||||
//当前执行的队列索引
|
||||
// queue.push(news_google);
|
||||
let closed_index = 0;
|
||||
|
||||
function sendMsg(obj) {
|
||||
|
@ -141,25 +146,9 @@ $(function () {
|
|||
chrome.tabs.query({}, function (tabs) {
|
||||
// 遍历每个标签页并关闭它们
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
chrome.tabs.remove(tabs[i].id);
|
||||
// chrome.tabs.remove(tabs[i].id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function sed_cont(id) {
|
||||
let message = {
|
||||
info: "来自popup的情书💌",
|
||||
};
|
||||
chrome.tabs.sendMessage(id, message, (res) => {
|
||||
// console.log("popup=>content");
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
chrome.tabs.onCreated.addListener((e) => {
|
||||
// sed_cont(id);
|
||||
console.log(e);
|
||||
console.log("创建了一个新的浏览器窗口");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -38,6 +38,16 @@ function is_mobile_web(){
|
|||
return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false
|
||||
}
|
||||
|
||||
//naver使用函数
|
||||
const all = async (r, id) => {
|
||||
for (let index = 0; index < 10; index++) {
|
||||
await delay(1)
|
||||
console.log(`共等待10秒当前${index+1}秒`)
|
||||
}
|
||||
send_close(id);
|
||||
};
|
||||
|
||||
|
||||
//naver使用函数
|
||||
const naver = async (r, id) => {
|
||||
let googelid_str = (elements = $(".gb_A.gb_Za.gb_0").attr("aria-label"));
|
||||
|
@ -45,9 +55,9 @@ const naver = async (r, id) => {
|
|||
const match = googelid_str.match(emailRegex);
|
||||
const email = match ? match[0] : null;
|
||||
console.log(`email:${email} r:${r} id${id}`)
|
||||
// let res = await to_background(email);
|
||||
// console.log(`res:${res} emall:${email}`);
|
||||
// await delay(10)
|
||||
let res = await to_background(email);
|
||||
console.log(`res:${res} emall:${email}`);
|
||||
await delay(10)
|
||||
// send_close(id);
|
||||
};
|
||||
/**
|
||||
|
@ -443,12 +453,9 @@ chrome.runtime.sendMessage(
|
|||
youtube(r, id);
|
||||
break;
|
||||
default:
|
||||
all()
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
// console.log(request);
|
||||
// sendResponse("我收到了你的情书,popup~");
|
||||
// });
|
||||
|
|
Loading…
Reference in New Issue