From 07b66a021d7a6d51bccb935a38d12be5c1b1cbf6 Mon Sep 17 00:00:00 2001 From: lingling <1077478963@qq.com> Date: Mon, 26 Aug 2024 14:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0youtube=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/popup.js | 15 ++++++---- lib/content.js | 78 ++++++++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/js/popup.js b/js/popup.js index 46b8e01..863fa26 100644 --- a/js/popup.js +++ b/js/popup.js @@ -98,15 +98,20 @@ $(function () { let a = await createTab("https://shopping.google.com/", "shopping"); return a; } + async function youtube() { + let a = await createTab("https://www.youtube.com/", "youtube"); + return a; + } //函数队列 let queue = []; // queue.push(play_finance);//好像js注入不进去 - // queue.push(shopping); - // queue.push(calendar); + queue.push(shopping); + queue.push(calendar); queue.push(mail); - // queue.push(play_google); - // queue.push(news_google); - // queue.push(youtube_shorts); + // queue.push(youtube); + queue.push(play_google); + queue.push(news_google); + queue.push(youtube_shorts); //乱序执行 此处有问题 // queue=shuffleArray(queue) //当前执行的队列索引 diff --git a/lib/content.js b/lib/content.js index 4157049..5c446ae 100644 --- a/lib/content.js +++ b/lib/content.js @@ -1,7 +1,7 @@ /** * 阻塞代码运行 * @param {*} n 秒数 - * @returns + * @returns */ function delay(n) { return new Promise(function (resolve) { @@ -12,7 +12,7 @@ function delay(n) { * 随机数生成 * @param {*} min 最小值 * @param {*} max 最大值 - * @returns + * @returns */ function getRandomInt(min, max) { min = Math.ceil(min); @@ -36,7 +36,7 @@ const naver = async (r, id) => { send_close(id); }; /** - * + * * @param {*} str 字符串 * @param {*} arr 需要匹配的字符串数组 * @returns boole @@ -52,8 +52,8 @@ function searchStringContainsArrayKeywords(str, arr) { /** * 谷歌商城 - * @param {*} r - * @param {*} id + * @param {*} r + * @param {*} id */ async function shopping(r, id) { let number = getRandomInt(2, 10); @@ -66,8 +66,8 @@ async function shopping(r, id) { /** * 谷歌日历 - * @param {*} r - * @param {*} id + * @param {*} r + * @param {*} id */ async function calendar(r, id) { await delay(3); @@ -90,36 +90,35 @@ async function calendar(r, id) { /** * 谷歌新闻 - * @param {*} r - * @param {*} id + * @param {*} r + * @param {*} id */ async function news_google(r, id) { //等待五秒怕加载速度过慢 await delay(3); //点击完整报道 try { - $('.jKHa4e')[0].click() - for (let index = 0; index < getRandomInt(3,5); index++) { - RandomIntscrollBy() - await delay(3) + $(".jKHa4e")[0].click(); + for (let index = 0; index < getRandomInt(3, 5); index++) { + RandomIntscrollBy(); + await delay(3); } - let new_array=$('.VDXfz') - let new_array_href=[] + 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}`) + 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++) { const element = new_array_href[index]; - let a= open(element) - await delay(3) - a.close() - + let a = open(element); + await delay(3); + a.close(); } } catch (error) { - console.log(error) + console.log(error); } send_close(id); } @@ -151,8 +150,8 @@ async function play_google(r, id) { } /** * 谷歌财经 - * @param {*} r - * @param {*} id + * @param {*} r + * @param {*} id */ async function play_finance(r, id) { await delay(5); @@ -177,8 +176,8 @@ async function play_finance(r, id) { /** * 谷歌邮箱 - * @param {*} r - * @param {*} id + * @param {*} r + * @param {*} id */ async function mail(r, id) { let emailReply = [ @@ -216,15 +215,22 @@ async function mail(r, id) { // console.log(mails_is_google[index].getElementsByClassName('yX xY')[0].children[1].children[0].children[0].getAttribute("email")) // console.log(mails_is_google[index].children[4].children[1].children[0].children[0].getAttribute("email")) //获取邮件发送人 - let mail_for = mails_is_google[index].getElementsByClassName('yX xY')[0].children[1].children[0].children[0].getAttribute("email") + let mail_for = mails_is_google[index] + .getElementsByClassName("yX xY")[0] + .children[1].children[0].children[0].getAttribute("email"); //是否回复 - let whether_or_not_to_reply_to= searchStringContainsArrayKeywords(mail_for,['google','youtube','gbcloud']) + let whether_or_not_to_reply_to = searchStringContainsArrayKeywords( + mail_for, + ["google", "youtube", "gbcloud"] + ); //逻辑取反 - whether_or_not_to_reply_to=!whether_or_not_to_reply_to - - console.log(`当前邮件发送人:${mail_for} 是否回复${whether_or_not_to_reply_to}`) + whether_or_not_to_reply_to = !whether_or_not_to_reply_to; + + console.log( + `当前邮件发送人:${mail_for} 是否回复${whether_or_not_to_reply_to}` + ); //邮箱回复 - if (getRandomInt(0, 1) == 0&&whether_or_not_to_reply_to) { + if (getRandomInt(0, 1) == 0 && whether_or_not_to_reply_to) { $(".amn >.ams.bkH").click(); await delay(getRandomInt(1, 5)); let text = emailReply[getRandomInt(0, emailReply.length - 1)]; @@ -297,9 +303,8 @@ async function youtube_shorts2(r, id) { } async function youtube(r, id) { - alert("youto"); // 点击长视频观看 - await delay(10); + await delay(5); //点击订阅 如果已经订阅过了就不用点 if ( $( @@ -401,6 +406,9 @@ chrome.runtime.sendMessage( case "shopping": shopping(r, id); break; + case "youtube": + youtube(r, id); + break; default: break; }