chrome_extensions/js/popup.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-08-19 17:05:34 +08:00
/*
* @Author: lingling 1077478963@qq.com
* @Date: 2024-08-19 09:47:04
* @LastEditors: lingling 1077478963@qq.com
* @LastEditTime: 2024-08-20 14:12:27
2024-08-19 17:05:34 +08:00
* @FilePath: \谷歌自动搜索邮箱自动点击v3\js\popup.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
2024-08-19 09:59:57 +08:00
$(function () {
2024-08-20 10:05:28 +08:00
// var id = 0, due = ['Dell', ' Lenovo ', "ASUS"], kme = 0 , name="";
var id = 0;
var name = "";
setTimeout(function () {
chrome.tabs.create(
{
url: "https://www.baidu.com/",
},
(e) => {
name = "naver";
id = e.id;
}
);
}, 2000);
function createTab(url, fname) {
return new Promise((resolve, reject) => {
chrome.tabs.create(
{
url: url,
},
(e) => {
name = fname;
id = e.id;
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve({ name: fname, id: e.id });
}
}
);
});
}
2024-08-20 10:05:28 +08:00
// 浏览器监听事件 每当有新页面生成就会执行
chrome.runtime.onMessage.addListener(function (
request,
sender,
sendResponse
) {
// 判断是产生一个新页面是
if (request.ty == "get") {
sendResponse({ name, id });
}
if (request.ty == "remove") {
chrome.tabs.remove(request.id);
}
return true;
});
2024-08-19 09:59:57 +08:00
async function text() {
let a= await createTab('https://www.youtube.com/','youtube')
return a
2024-08-20 10:05:28 +08:00
}
// async function text2() {
// let a= await createTab('https://www.so.com/','360')
// return a
// }
2024-08-20 10:05:28 +08:00
//函数队列
let queue = [];
queue.push(text)
// queue.push(text2)
2024-08-20 10:05:28 +08:00
//当前执行的队列索引
let closed_index=0;
function sendMsg(obj){
chrome.runtime.sendMessage(obj, res => {
// 答复
console.log('popup=>content')
console.log(res)
})
}
// 浏览器监听事件 关闭标签页时就会执行
chrome.tabs.onRemoved.addListener(async (windowId) => {
console.log("Closed window: " + windowId);
if(closed_index<queue.length){
2024-08-20 10:05:28 +08:00
let tmp=await queue[closed_index]()
// console.log(tmp)
2024-08-20 10:05:28 +08:00
sendMsg(tmp)
closed_index++
// sendResponse({ name, id });
}
});
chrome.tabs.onCreated.addListener(
(e)=>{console.log(e);}
)
2024-08-19 17:05:34 +08:00
});