chrome_extensions_phone/lib/content.js

301 lines
8.0 KiB
JavaScript
Raw Permalink Normal View History

2024-08-24 11:17:58 +08:00
/**
* 阻塞代码运行
* @param {*} n 秒数
2024-08-26 14:34:55 +08:00
* @returns
2024-08-24 11:17:58 +08:00
*/
2024-08-19 17:05:34 +08:00
function delay(n) {
return new Promise(function (resolve) {
setTimeout(resolve, n * 1000);
});
}
2024-08-24 11:17:58 +08:00
/**
* 随机数生成
* @param {*} min 最小值
* @param {*} max 最大值
2024-08-26 14:34:55 +08:00
* @returns
2024-08-24 11:17:58 +08:00
*/
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
2024-08-24 11:17:58 +08:00
/**
* 随机滑动函数
* @param {*} y 滑动像素 不传递默认随机
*/
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
2024-09-21 21:58:25 +08:00
/**
2024-09-21 22:36:11 +08:00
*
2024-09-21 21:58:25 +08:00
* @param {*} element html对象
* @param {*} direction 操作 down|up|left|right
*/
function triggerSwipeEvent(element, direction) {
const touchStart = new Touch({
identifier: Date.now(),
target: element,
clientX: 0,
clientY: 0,
screenX: 0,
screenY: 0,
pageX: 0,
pageY: 0,
});
const touchEnd = new Touch({
identifier: Date.now() + 1,
target: element,
2024-09-21 22:36:11 +08:00
clientX: direction === "left" ? -100 : direction === "right" ? 100 : 0,
clientY: direction === "up" ? -500 : direction === "down" ? 100 : 0,
screenX: direction === "left" ? -100 : direction === "right" ? 100 : 0,
screenY: direction === "up" ? -500 : direction === "down" ? 100 : 0,
pageX: direction === "left" ? -100 : direction === "right" ? 100 : 0,
pageY: direction === "up" ? -500 : direction === "down" ? 100 : 0,
2024-09-21 21:58:25 +08:00
});
const touchMove = new Touch({
identifier: Date.now() + 2,
target: element,
2024-09-21 22:36:11 +08:00
clientX: direction === "left" ? -50 : direction === "right" ? 50 : 0,
clientY: direction === "up" ? -500 : direction === "down" ? 50 : 0,
screenX: direction === "left" ? -50 : direction === "right" ? 50 : 0,
screenY: direction === "up" ? -500 : direction === "down" ? 50 : 0,
pageX: direction === "left" ? -50 : direction === "right" ? 50 : 0,
pageY: direction === "up" ? -500 : direction === "down" ? 50 : 0,
2024-09-21 21:58:25 +08:00
});
2024-09-21 22:36:11 +08:00
const touchStartEvent = new TouchEvent("touchstart", {
2024-09-21 21:58:25 +08:00
touches: [touchStart],
targetTouches: [touchStart],
changedTouches: [touchStart],
cancelable: true,
bubbles: true,
});
2024-09-21 22:36:11 +08:00
const touchMoveEvent = new TouchEvent("touchmove", {
2024-09-21 21:58:25 +08:00
touches: [touchMove],
targetTouches: [touchMove],
changedTouches: [touchMove],
cancelable: true,
bubbles: true,
});
2024-09-21 22:36:11 +08:00
const touchEndEvent = new TouchEvent("touchend", {
2024-09-21 21:58:25 +08:00
touches: [],
targetTouches: [],
changedTouches: [touchEnd],
cancelable: true,
bubbles: true,
});
element.dispatchEvent(touchStartEvent);
element.dispatchEvent(touchMoveEvent);
element.dispatchEvent(touchEndEvent);
}
2024-08-19 17:05:34 +08:00
//naver使用函数
const naver = async (r, id) => {
send_close(id);
2024-08-19 17:05:34 +08:00
};
2024-08-24 11:17:58 +08:00
/**
2024-08-26 14:34:55 +08:00
*
2024-08-24 11:17:58 +08:00
* @param {*} str 字符串
* @param {*} arr 需要匹配的字符串数组
* @returns boole
*/
function searchStringContainsArrayKeywords(str, arr) {
for (let i = 0; i < arr.length; i++) {
if (str.includes(arr[i])) {
return true;
}
}
return false;
}
/**
* 谷歌商城
2024-08-26 14:34:55 +08:00
* @param {*} r
* @param {*} id
*/
2024-08-22 16:25:33 +08:00
async function shopping(r, id) {
let number = getRandomInt(2, 10);
for (let index = 0; index < number; index++) {
2024-09-22 22:14:42 +08:00
for (let index = 0; index < getRandomInt(2, 5); index++) {
RandomIntscrollBy();
await delay(getRandomInt(5, 10));
}
//获取所有的商品链接
let sp = document.getElementsByClassName(
"gkQHve RmEs5b zypKDd aKoISd RycMEf"
);
//触发点击事件
sp[getRandomInt(0, sp.length - 1)].click();
await delay(getRandomInt(10, 20));
//获取关闭按钮
let close = document.getElementsByClassName(
"ioQ39e wv9iH MjJqGe cd29Sd"
)[0];
close.click();
await delay(getRandomInt(2, 5));
2024-08-22 16:25:33 +08:00
}
send_close(id);
}
/**
* 谷歌新闻
2024-08-26 14:34:55 +08:00
* @param {*} r
* @param {*} id
*/
2024-08-21 11:30:52 +08:00
async function news_google(r, id) {
//等待五秒怕加载速度过慢
await delay(3);
2024-09-22 22:14:42 +08:00
//滑动次数
2024-09-22 22:54:01 +08:00
let sum = getRandomInt(5, 9);
2024-09-21 21:58:25 +08:00
for (let index = 0; index < sum; index++) {
2024-09-21 22:36:11 +08:00
RandomIntscrollBy();
await delay(getRandomInt(5, 10));
}
2024-09-22 22:54:01 +08:00
let news_array = $(".cDgn2c");
//随机点击模块
news_array[getRandomInt(0, news_array.length - 1)].click();
for (let index = 0; index < getRandomInt(3, 8); index++) {
RandomIntscrollBy();
await delay(getRandomInt(3, 8));
}
let new_array = $(".VDXfz");
let new_array_href = [];
for (let index = 0; index < new_array.length; index++) {
const element = new_array[index];
console.log(element.getAttribute("href"));
let url = element.getAttribute("href").replace(/\./g, "");
new_array_href.push(`https://news.google.com${url}`);
}
// for (let index = 0; index < new_array_href.length; index++) {
//这里只打开4个链接太多了有毒
for (let index = 0; index < 4; index++) {
const element = new_array_href[index];
let a = open(element);
// console.log(JSON.stringify(a))
await delay(3);
a.close();
}
2024-08-21 17:35:28 +08:00
send_close(id);
}
//谷歌商店浏览
async function play_google(r, id) {
//等待五秒怕加载速度过慢
await delay(5);
//滑动次数
let a = getRandomInt(3, 5);
for (let index = 0; index < a; index++) {
RandomIntscrollBy();
await delay(getRandomInt(0, 5));
}
//热门游戏随机列表 直接触发点击事件就行
2024-09-22 22:14:42 +08:00
let popular_games = document.querySelectorAll("a.Si6A0c.itIJzb");
for (let index = 0; index < getRandomInt(3, 5); index++) {
try {
popular_games[getRandomInt(0, popular_games.length - 1)].click();
} catch (error) {
2024-09-22 22:54:01 +08:00
console.log(error);
2024-09-22 22:14:42 +08:00
}
let a = getRandomInt(3, 5);
for (let index = 0; index < a; index++) {
RandomIntscrollBy();
await delay(getRandomInt(0, 5));
}
$(".f0UV3d").click();
await delay(getRandomInt(5, 10));
}
2024-08-21 17:35:28 +08:00
await delay(getRandomInt(5, 10));
//
send_close(id);
}
2024-08-21 11:30:52 +08:00
async function youtube_shorts2(r, id) {
//等待五秒怕加载速度过慢
await delay(5);
//观看次数
2024-09-21 21:58:25 +08:00
for (let index = 0; index < 5; index++) {
2024-09-21 22:36:11 +08:00
// 使用示例:
2024-09-21 21:58:25 +08:00
// let element = $('.YtShortsCarouselCarouselItem.carousel-item[aria-hidden$="false"]')
2024-09-21 22:36:11 +08:00
let element = document.querySelector(
".YtShortsCarouselCarouselItem.carousel-item"
);
triggerSwipeEvent(element, "up"); // 触发向左滑动事件
await delay(getRandomInt(10, 30));
2024-08-21 11:30:52 +08:00
}
//看完关闭窗口
send_close(id);
}
async function youtube(r, id) {
2024-09-22 22:14:42 +08:00
async function whict() {
await delay(5);
for (let index = 0; index < getRandomInt(5, 10); index++) {
RandomIntscrollBy();
}
let all_video = $(".media-item-thumbnail-container");
all_video[getRandomInt(0, all_video.length - 1)].click();
2024-09-24 12:10:16 +08:00
// if(getRandomInt(0,1)==0){
// //点赞
// document.getElementsByClassName('yt-spec-touch-feedback-shape__fill')[3].click()
// //订阅
// document.getElementsByClassName('yt-spec-touch-feedback-shape__fill')[2].click()
// }
await delay(getRandomInt(300, 1800));
2024-09-22 22:14:42 +08:00
}
for (let index = 0; index < getRandomInt(5, 10); index++) {
await whict();
}
2024-09-21 21:58:25 +08:00
//看完关闭窗口
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-09-21 22:36:11 +08:00
let functoons = [
{ name: "naver", funct: naver },
{ name: "youtube", funct: youtube },
{ name: "youtube_shorts", funct: youtube_shorts2 },
{ name: "news_google", funct: news_google },
{ name: "play_google", funct: play_google },
{ name: "shopping", funct: shopping },
];
2024-09-22 22:54:01 +08:00
let is_Match = false;
2024-09-21 22:36:11 +08:00
for (let index = 0; index < functoons.length; index++) {
// const element = functoons[index];
2024-09-22 22:14:42 +08:00
let name = functoons[index].name;
let funct = functoons[index].funct;
if (r == name) {
2024-09-22 22:54:01 +08:00
is_Match = true;
2024-09-22 22:14:42 +08:00
funct(r, id);
2024-09-21 22:36:11 +08:00
}
2024-08-19 17:05:34 +08:00
}
}
);
2024-08-20 10:05:28 +08:00
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(request);
sendResponse("我收到了你的情书popup~");
});