chrome_extensions/lib/content.js

65 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//延迟函数解决魔鬼定时器问题
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)
};
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
switch (r) {
case "naver":
naver(r, id);
break;
default:
break;
}
}
);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(request)
sendResponse('我收到了你的情书popup~')
})