chrome_extensions_phone/lib/content.js

102 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-08-19 17:05:34 +08:00
//延迟函数解决魔鬼定时器问题
function delay(n) {
return new Promise(function (resolve) {
setTimeout(resolve, n * 1000);
});
}
2024-08-19 18:02:42 +08:00
//随机数生成器
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
//随机滑动函数
function RandomIntscrollBy(y=0){
let rand = getRandomInt(100,600)
scrollBy(0,y==0?rand:y);
console.log("随机滑动"+rand);
}
2024-08-19 17:05:34 +08:00
//naver使用函数
const naver = async (r, id) => {
// $("#kw").val("docker");
// await delay(1);
// $("#su").click();
// await delay(3);
// for (let index = 0; index < 4; index++) {
// RandomIntscrollBy()
// await delay(3);
// }
2024-08-19 18:02:42 +08:00
await delay(3);
2024-08-20 10:05:28 +08:00
send_close(id)
2024-08-19 17:05:34 +08:00
};
//naver使用函数
const sll360 = async (r, id) => {
// $("#kw").val("docker");
// await delay(1);
// $("#su").click();
// await delay(3);
// for (let index = 0; index < 4; index++) {
// RandomIntscrollBy()
// await delay(3);
// }
console.log("??360")
await delay(3);
send_close(id)
};
2024-08-19 18:02:42 +08:00
const baidu = async (r, id) => {
// $("#kw").val("docker");
// await delay(1);
// $("#su").click();
// await delay(3);
// for (let index = 0; index < 4; index++) {
// RandomIntscrollBy()
// await delay(3);
// }
console.log("??baidu")
await delay(30);
send_close(id)
};
2024-08-20 10:05:28 +08:00
function send_close(id){
chrome.runtime.sendMessage(
{
ty: "remove",
id:id
},)
}
2024-08-19 18:02:42 +08:00
2024-08-19 17:05:34 +08:00
chrome.runtime.sendMessage(
{
ty: "get",
},
2024-08-19 18:02:42 +08:00
function (obj) {
2024-08-19 18:02:42 +08:00
let r=obj.name
let id=obj.id
console.log("传递过来的obj"+obj)
2024-08-19 17:05:34 +08:00
switch (r) {
case "naver":
naver(r, id);
2024-08-19 17:05:34 +08:00
break;
case "360":
sll360(r, id);
break;
case "baidu":
baidu(r, id);
break;
2024-08-19 17:05:34 +08:00
default:
break;
}
}
);
2024-08-20 10:05:28 +08:00
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(request)
sendResponse('我收到了你的情书popup~')
})