102 lines
1.9 KiB
JavaScript
102 lines
1.9 KiB
JavaScript
//延迟函数解决魔鬼定时器问题
|
||
function delay(n) {
|
||
return new Promise(function (resolve) {
|
||
setTimeout(resolve, n * 1000);
|
||
});
|
||
}
|
||
//随机数生成器
|
||
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);
|
||
}
|
||
|
||
//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);
|
||
// }
|
||
await delay(3);
|
||
send_close(id)
|
||
};
|
||
|
||
//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)
|
||
};
|
||
|
||
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)
|
||
};
|
||
|
||
function send_close(id){
|
||
chrome.runtime.sendMessage(
|
||
{
|
||
ty: "remove",
|
||
id:id
|
||
},)
|
||
}
|
||
|
||
chrome.runtime.sendMessage(
|
||
{
|
||
ty: "get",
|
||
},
|
||
function (obj) {
|
||
|
||
let r=obj.name
|
||
let id=obj.id
|
||
console.log("传递过来的obj"+obj)
|
||
switch (r) {
|
||
case "naver":
|
||
naver(r, id);
|
||
break;
|
||
|
||
case "360":
|
||
sll360(r, id);
|
||
break;
|
||
case "baidu":
|
||
baidu(r, id);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
);
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||
console.log(request)
|
||
sendResponse('我收到了你的情书,popup~')
|
||
}) |