准备更新v3
This commit is contained in:
parent
b74e21ed7b
commit
3faa458151
103
js/popup.js
103
js/popup.js
|
@ -2,41 +2,82 @@
|
|||
* @Author: lingling 1077478963@qq.com
|
||||
* @Date: 2024-08-19 09:47:04
|
||||
* @LastEditors: lingling 1077478963@qq.com
|
||||
* @LastEditTime: 2024-08-19 17:53:29
|
||||
* @LastEditTime: 2024-08-20 10:01:56
|
||||
* @FilePath: \谷歌自动搜索邮箱自动点击v3\js\popup.js
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
$(function () {
|
||||
// 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);
|
||||
// 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);
|
||||
// 浏览器监听事件 每当有新页面生成就会执行
|
||||
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;
|
||||
});
|
||||
|
||||
// 浏览器监听事件 每当有新页面生成就会执行
|
||||
chrome.runtime.onMessage.addListener(function (
|
||||
request,
|
||||
sender,
|
||||
sendResponse
|
||||
) {
|
||||
// 判断是产生一个新页面是
|
||||
if (request.ty == "get") {
|
||||
console.log(id)
|
||||
sendResponse({name,id});
|
||||
}
|
||||
// if (request.ty == "remove") {
|
||||
// async function text() {
|
||||
// let a= await chrome.tabs.create(
|
||||
// {
|
||||
// url: "https://www.baidu.com/",
|
||||
// }
|
||||
// );
|
||||
// console.log(a)
|
||||
// return {'name':'baidu',id:a.id}
|
||||
// }
|
||||
async function createTabAndGetId() {
|
||||
let newTab = await chrome.tabs.create({url: "https://www.example.com"});
|
||||
console.log('New tab ID:', newTab);
|
||||
return newTab;
|
||||
}
|
||||
//函数队列
|
||||
let queue = [];
|
||||
queue.push(createTabAndGetId)
|
||||
//当前执行的队列索引
|
||||
let closed_index=0;
|
||||
|
||||
// sendResponse({name,id});
|
||||
// }
|
||||
return true;
|
||||
});
|
||||
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){
|
||||
let tmp=await queue[closed_index]()
|
||||
sendMsg(tmp)
|
||||
closed_index++
|
||||
// sendResponse({ name, id });
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
chrome.tabs.onCreated.addListener(
|
||||
(e)=>{console.log(e);}
|
||||
)
|
||||
});
|
||||
|
|
|
@ -29,11 +29,18 @@ const naver = async (r, id) => {
|
|||
await delay(3);
|
||||
}
|
||||
await delay(3);
|
||||
|
||||
send_close(id)
|
||||
};
|
||||
|
||||
|
||||
function send_close(){}
|
||||
|
||||
function send_close(id){
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
ty: "remove",
|
||||
id:id
|
||||
},)
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
|
@ -52,3 +59,7 @@ chrome.runtime.sendMessage(
|
|||
}
|
||||
}
|
||||
);
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
console.log(request)
|
||||
sendResponse('我收到了你的情书,popup~')
|
||||
})
|
Loading…
Reference in New Issue