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 ) {
2024-08-20 14:26:52 +08:00
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 滑动像素 不传递默认随机
* /
2024-08-20 14:26:52 +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
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 ,
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 ,
} ) ;
const touchMove = new Touch ( {
identifier : Date . now ( ) + 2 ,
target : element ,
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 ,
} ) ;
const touchStartEvent = new TouchEvent ( 'touchstart' , {
touches : [ touchStart ] ,
targetTouches : [ touchStart ] ,
changedTouches : [ touchStart ] ,
cancelable : true ,
bubbles : true ,
} ) ;
const touchMoveEvent = new TouchEvent ( 'touchmove' , {
touches : [ touchMove ] ,
targetTouches : [ touchMove ] ,
changedTouches : [ touchMove ] ,
cancelable : true ,
bubbles : true ,
} ) ;
const touchEndEvent = new TouchEvent ( 'touchend' , {
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 ) => {
2024-08-20 14:26:52 +08:00
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-20 14:26:52 +08:00
2024-08-26 09:20:29 +08:00
/ * *
* 谷歌商城
2024-08-26 14:34:55 +08:00
* @ param { * } r
* @ param { * } id
2024-08-26 09:20:29 +08:00
* /
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 ++ ) {
RandomIntscrollBy ( ) ;
await delay ( getRandomInt ( 3 , 7 ) ) ;
}
send _close ( id ) ;
}
2024-08-22 14:06:42 +08:00
2024-08-26 09:20:29 +08:00
/ * *
* 谷歌新闻
2024-08-26 14:34:55 +08:00
* @ param { * } r
* @ param { * } id
2024-08-26 09:20:29 +08:00
* /
2024-08-21 11:30:52 +08:00
async function news _google ( r , id ) {
//等待五秒怕加载速度过慢
2024-08-26 11:01:59 +08:00
await delay ( 3 ) ;
//点击完整报道
2024-09-21 21:58:25 +08:00
let sum = getRandomInt ( 10 , 50 )
for ( let index = 0 ; index < sum ; index ++ ) {
RandomIntscrollBy ( )
await delay ( getRandomInt ( 5 , 10 ) ) ;
2024-08-26 11:01:59 +08:00
}
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 ) ) ;
}
//点击推荐
if ( getRandomInt ( 0 , 1 ) == 0 ) {
$ ( ".Pdcv8e" ) . click ( ) ;
await delay ( getRandomInt ( 5 , 10 ) ) ;
//返回主页
$ ( "#kO001e > header > nav > a" ) . click ( ) ;
}
//热门游戏随机列表 直接触发点击事件就行
let popular _games = $ (
"#yDmH0d > c-wiz.SSPGKf.glB9Ve > div > div > div.N4FjMb.Z97G4e > c-wiz > div > c-wiz > c-wiz:nth-child(4) > c-wiz > section > div > div > div > div > div.aoJE7e.b0ZfVe"
) . children ;
await delay ( getRandomInt ( 5 , 10 ) ) ;
//
send _close ( id ) ;
}
2024-08-26 14:34:55 +08:00
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 ++ ) {
// 使用示例:
// let element = $('.YtShortsCarouselCarouselItem.carousel-item[aria-hidden$="false"]')
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 ) ;
}
2024-08-20 14:26:52 +08:00
async function youtube ( r , id ) {
// 点击长视频观看
2024-08-26 14:34:55 +08:00
await delay ( 5 ) ;
2024-09-21 21:58:25 +08:00
$ ( '#app > div > ytm-browse > ytm-single-column-browse-results-renderer > div > div > ytm-tab-renderer > ytm-rich-grid-renderer > div > div.rich-grid-renderer-contents > ytm-rich-item-renderer:nth-child(2) > ytm-video-with-context-renderer > ytm-media-item > a > ytm-thumbnail-cover > img' ) . click ( )
await delay ( getRandomInt ( 2000 , 3600 ) ) ;
//看完关闭窗口
2024-08-20 14:26:52 +08:00
send _close ( id ) ;
}
2024-09-21 21:58:25 +08:00
2024-08-20 14:26:52 +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-20 14:26:52 +08:00
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" :
2024-08-20 14:26:52 +08:00
naver ( r , id ) ;
2024-08-19 17:05:34 +08:00
break ;
2024-08-20 14:26:52 +08:00
case "youtube" :
youtube ( r , id ) ;
2024-08-20 11:02:53 +08:00
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-21 17:35:28 +08:00
case "play_google" :
play _google ( r , id ) ;
break ;
2024-08-22 16:25:33 +08:00
case "shopping" :
shopping ( r , id ) ;
break ;
2024-08-26 14:34:55 +08:00
case "youtube" :
youtube ( r , id ) ;
break ;
2024-08-19 17:05:34 +08:00
default :
2024-09-21 21:58:25 +08:00
naver ( r , id ) ;
2024-08-19 17:05:34 +08:00
break ;
}
}
) ;
2024-08-20 10:05:28 +08:00
chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
2024-08-20 14:26:52 +08:00
console . log ( request ) ;
sendResponse ( "我收到了你的情书, popup~" ) ;
} ) ;