chrome_extensions/lib/content.js

331 lines
9.4 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;
}
2024-08-19 18:02:42 +08:00
//随机滑动函数
function RandomIntscrollBy(y = 0) {
let rand = getRandomInt(100, 600);
scrollBy(0, y == 0 ? rand : y);
console.log("随机滑动" + rand);
2024-08-19 18:02:42 +08:00
}
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-21 11:30:52 +08:00
await delay(1);
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);
};
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);
};
//youto短视频
async function youtube_shorts(r, id) {
i = 0;
// 随机执行次数
randTime = Math.floor(Math.random() * 16) + 15;
console.log("执行", randTime, "次");
// 根据次数随机每次观看的时长
const list = [];
for (let i = 0; i < randTime; i++) {
// 生成 1 到 5 之间的随机整数
const randomNum = Math.floor(Math.random() * 44) + 5; //44
// 将随机数添加到列表中
list.push(randomNum * 1000);
}
console.log("每个视频的观看时长:", list);
// 首次进入判断是否播放
var playing =
document.querySelector("div.playing-mode") == null ? false : true;
var paused = document.querySelector("div.paused-mode") == null ? false : true;
console.log("playing", playing, "paused", paused);
if (playing) {
console.log("首次进入在播放!");
} else {
await delay(5);
var playButton = document.getElementsByClassName(
"ytp-large-play-button ytp-button"
)[0];
playButton.click();
console.log("点击了播放!");
}
// 执行
2024-08-21 11:30:52 +08:00
// var dingshiqi_duanshipin = setInterval(() => {
// run((randomTime = list[i]));
// }, list[i] + 2000);
while (true) {
await run((randomTime = list[i]));
// await delay((list[i] + 2000)/1000);
}
// 定义一个执行函数
async function run(randomTime) {
// 执行randTime次后停止
console.log(
"总计:",
randTime,
"次,当前第:",
i + 1,
"次,观看时长:",
randomTime / 1000,
"s"
);
if (i == randTime) {
console.log("已经执行", randTime, "次,关闭当前标签页!");
2024-08-21 11:30:52 +08:00
// clearInterval(dingshiqi_duanshipin);
send_close(id);
}
// 点赞
var button = document.querySelector(
".yt-spec-button-shape-next--icon-button"
);
console.log("是否已点赞:", button.getAttribute("aria-pressed"));
button.click();
bao = $("#shorts-inner-container ytd-reel-video-renderer");
for (j = 0; j < bao.length; j++) {
// 如果是当前正在播放的视频 点赞+订阅
if (typeof $(bao[j]).attr("is-active") == "string") {
dianzan = $(bao[j]).find("button")[23];
dingyue = $(bao[j]).find("button")[20];
// 点赞
if ($(dianzan).is(".yt-spec-button-shape-next--tonal"))
$(dianzan).click();
// 订阅
if ($(dingyue).is(".yt-spec-button-shape-next--filled"))
$(dingyue).click();
j = bao.length;
}
}
// 下一集 randomTime - 2s
await delay(randomTime);
$("div #navigation-button-down button").click();
console.log("点击了下一个视频");
i++;
}
// 定时器
let timer = setTimeout(function () {
location.reload();
console.log("页面长时间无响应");
}, 60000); // 设置超时时间为 5 秒钟
// 在每次页面有响应的时候,清除计时器即可
window.addEventListener("click", function () {
console.log("页面有响应");
// 清除计时器
clearTimeout(timer);
// 判断是否再播放
var playing =
document.querySelector("div.playing-mode") == null ? false : true;
var paused =
document.querySelector("div.paused-mode") == null ? false : true;
console.log("播放:", playing, "暂停:", paused);
if (playing) {
console.log("已播放!");
} else {
var playButton = document.getElementsByClassName(
"ytp-large-play-button ytp-button"
)[0];
playButton.click();
console.log("点击了播放!");
}
});
send_close(id);
}
2024-08-21 11:30:52 +08:00
async function news_google(r, id) {
console.log("加在完成开始等待8秒")
//等待五秒怕加载速度过慢
await delay(10);
console.log("等待8秒完成")
//焦点新闻 数量
let new_length = $(".KDoq1").length;
//点击会创建新标签暂时没办法控制
// let rand_new_index=getRandomInt(0,new_length)
//点击焦点新闻
$("#i10").click();
$(".KDoq1")[0].click();
// console.log( $("#i10"))
// await delay(10);
// let the_number_of_swipes = getRandomInt(3, 6);
// for (let index = 0; index < the_number_of_swipes; index++) {
// RandomIntscrollBy();
// await delay(getRandomInt(10, 30));
// }
2024-08-21 13:56:31 +08:00
let x=$(".WwrzSb").length,y=1,shu=parseInt(Math.random() * (x - y + 1) + y);
$(".WwrzSb").eq(shu)[0].click();
scrollBy(0, 153);
2024-08-21 11:30:52 +08:00
send_close(id);
}
async function youtube_shorts2(r, id) {
//等待五秒怕加载速度过慢
await delay(5);
//观看次数
2024-08-21 13:56:31 +08:00
let views = getRandomInt(50, 100);
2024-08-21 11:30:52 +08:00
for (let index = 0; index < views; index++) {
//观看多少秒
let watch_time = getRandomInt(10, 30);
await delay(getRandomInt(2, 5));
//随机暂停播放
if (getRandomInt(0, 1) == 0) {
$(".video-stream.html5-main-video").click();
await delay(getRandomInt(2, 5));
$(".video-stream.html5-main-video").click();
await delay(watch_time);
}
//点赞
// $('.yt-spec-button-shape-next.yt-spec-button-shape-next--tonal.yt-spec-button-shape-next--mono.yt-spec-button-shape-next--size-l.yt-spec-button-shape-next--icon-button').click()
//评论区操作
if (getRandomInt(0, 1) == 0) {
//打开评论区
$(
"#comments-button > ytd-button-renderer > yt-button-shape > label > button > yt-touch-feedback-shape > div > div.yt-spec-touch-feedback-shape__fill"
).click();
await delay(getRandomInt(3, 5));
//随机滑动评论区
2024-08-21 13:56:31 +08:00
// RandomIntscrollBy();
2024-08-21 11:30:52 +08:00
//关闭评论区
$(
"#visibility-button > ytd-button-renderer > yt-button-shape > button > yt-touch-feedback-shape > div > div.yt-spec-touch-feedback-shape__stroke"
).click();
}
2024-08-21 13:56:31 +08:00
//下一个视频
$('#navigation-button-down > ytd-button-renderer > yt-button-shape > button > yt-touch-feedback-shape > div > div.yt-spec-touch-feedback-shape__stroke').click()
2024-08-21 11:30:52 +08:00
}
//看完关闭窗口
send_close(id);
}
async function youtube(r, id) {
2024-08-21 11:30:52 +08:00
alert("youto");
// 点击长视频观看
await delay(10);
2024-08-21 13:56:31 +08:00
//点击订阅 如果已经订阅过了就不用点
if($('div ytd-subscribe-button-renderer yt-smartimation yt-button-shape button').eq(0).is('.yt-spec-button-shape-next--filled'))
$('div ytd-subscribe-button-renderer yt-smartimation yt-button-shape button').eq(0).click();
// 点赞
if($('div ytd-segmented-like-dislike-button-renderer div ytd-toggle-button-renderer yt-button-shape button').is('.yt-spec-button-shape-next--tonal'))
$('div ytd-segmented-like-dislike-button-renderer div ytd-toggle-button-renderer yt-button-shape button').eq(0).click();
$('button .yt-spec-button-shape-next--size-m').click();
next_vido=Math.round(Math.random()*$('contents ytd-compact-video-renderer div ytd-thumbnail a').length);
if (next_vido == $('contents ytd-compact-video-renderer div ytd-thumbnail a').length)
next_vido=next_vido-1;
$('#contents ytd-compact-video-renderer div ytd-thumbnail a').eq(next_vido)[0].click();
}
function ServiceLogin(r, id) {
let mkeww = 0,
mue = setInterval(function () {
if ($("form ul>li img").length) {
clearInterval(mue);
setTimeout(function () {
$("form ul>li img").eq(0)[0].click();
}, 1900);
} else {
mkeww++;
if (mkeww > 106) {
clearInterval(mue);
}
}
}, 500);
send_close(id);
}
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) {
let r = obj.name;
let id = obj.id;
console.log("传递过来的obj" + JSON.stringify(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;
case "youtube":
youtube(r, id);
break;
2024-08-21 11:30:52 +08:00
case "youtube_shorts":
youtube_shorts2(r, id);
break;
case "news_google":
news_google(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~");
});