缩短大量代码行
This commit is contained in:
parent
bd71f3ac18
commit
febcf2ed9a
39
js/popup.js
39
js/popup.js
|
@ -60,35 +60,14 @@ $(function () {
|
|||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
async function youtube_shorts() {
|
||||
let a = await createTab(
|
||||
"https://www.youtube.com/shorts/",
|
||||
"youtube_shorts"
|
||||
);
|
||||
return a;
|
||||
}
|
||||
async function news_google() {
|
||||
let a = await createTab("https://news.google.com/", "news_google");
|
||||
return a;
|
||||
}
|
||||
async function play_google() {
|
||||
let a = await createTab("https://play.google.com/", "play_google");
|
||||
return a;
|
||||
}
|
||||
async function shopping() {
|
||||
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(shopping);
|
||||
queue.push(play_google);
|
||||
queue.push(news_google);
|
||||
let queue = [
|
||||
{ url: "https://www.youtube.com/", tip: "youtube" },
|
||||
{ url: "https://news.google.com/", tip: "news_google" },
|
||||
{ url: "https://shopping.google.com/", tip: "shopping" },
|
||||
{ url: "https://play.google.com/", tip: "play_google" },
|
||||
];
|
||||
|
||||
//当前执行的队列索引
|
||||
let closed_index = 0;
|
||||
|
||||
|
@ -103,7 +82,9 @@ $(function () {
|
|||
// 浏览器监听事件 关闭标签页时就会执行
|
||||
chrome.tabs.onRemoved.addListener(async (windowId) => {
|
||||
if (closed_index < queue.length) {
|
||||
let tmp = await queue[closed_index]();
|
||||
let url = queue[closed_index].url;
|
||||
let tip = queue[closed_index].tip;
|
||||
let tmp = await createTab(url, tip);
|
||||
// console.log(tmp)
|
||||
sendMsg(tmp);
|
||||
closed_index++;
|
||||
|
|
|
@ -31,7 +31,7 @@ function RandomIntscrollBy(y = 0) {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {*} element html对象
|
||||
* @param {*} direction 操作 down|up|left|right
|
||||
*/
|
||||
|
@ -51,26 +51,26 @@ function triggerSwipeEvent(element, direction) {
|
|||
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,
|
||||
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,
|
||||
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', {
|
||||
const touchStartEvent = new TouchEvent("touchstart", {
|
||||
touches: [touchStart],
|
||||
targetTouches: [touchStart],
|
||||
changedTouches: [touchStart],
|
||||
|
@ -78,7 +78,7 @@ function triggerSwipeEvent(element, direction) {
|
|||
bubbles: true,
|
||||
});
|
||||
|
||||
const touchMoveEvent = new TouchEvent('touchmove', {
|
||||
const touchMoveEvent = new TouchEvent("touchmove", {
|
||||
touches: [touchMove],
|
||||
targetTouches: [touchMove],
|
||||
changedTouches: [touchMove],
|
||||
|
@ -86,7 +86,7 @@ function triggerSwipeEvent(element, direction) {
|
|||
bubbles: true,
|
||||
});
|
||||
|
||||
const touchEndEvent = new TouchEvent('touchend', {
|
||||
const touchEndEvent = new TouchEvent("touchend", {
|
||||
touches: [],
|
||||
targetTouches: [],
|
||||
changedTouches: [touchEnd],
|
||||
|
@ -132,7 +132,6 @@ async function shopping(r, id) {
|
|||
send_close(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 谷歌新闻
|
||||
* @param {*} r
|
||||
|
@ -142,10 +141,10 @@ async function news_google(r, id) {
|
|||
//等待五秒怕加载速度过慢
|
||||
await delay(3);
|
||||
//点击完整报道
|
||||
let sum=getRandomInt(10,50)
|
||||
let sum = getRandomInt(10, 50);
|
||||
for (let index = 0; index < sum; index++) {
|
||||
RandomIntscrollBy()
|
||||
await delay(getRandomInt(5,10));
|
||||
RandomIntscrollBy();
|
||||
await delay(getRandomInt(5, 10));
|
||||
}
|
||||
send_close(id);
|
||||
}
|
||||
|
@ -176,18 +175,18 @@ async function play_google(r, id) {
|
|||
send_close(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function youtube_shorts2(r, id) {
|
||||
//等待五秒怕加载速度过慢
|
||||
await delay(5);
|
||||
//观看次数
|
||||
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))
|
||||
let element = document.querySelector(
|
||||
".YtShortsCarouselCarouselItem.carousel-item"
|
||||
);
|
||||
triggerSwipeEvent(element, "up"); // 触发向左滑动事件
|
||||
await delay(getRandomInt(10, 30));
|
||||
}
|
||||
//看完关闭窗口
|
||||
send_close(id);
|
||||
|
@ -196,14 +195,14 @@ async function youtube_shorts2(r, id) {
|
|||
async function youtube(r, id) {
|
||||
// 点击长视频观看
|
||||
await delay(5);
|
||||
$('#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()
|
||||
$(
|
||||
"#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));
|
||||
//看完关闭窗口
|
||||
send_close(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function send_close(id) {
|
||||
chrome.runtime.sendMessage({
|
||||
ty: "remove",
|
||||
|
@ -219,31 +218,23 @@ chrome.runtime.sendMessage(
|
|||
let r = obj.name;
|
||||
let id = obj.id;
|
||||
console.log("传递过来的obj" + JSON.stringify(obj));
|
||||
switch (r) {
|
||||
case "naver":
|
||||
naver(r, id);
|
||||
break;
|
||||
case "youtube":
|
||||
youtube(r, id);
|
||||
break;
|
||||
case "youtube_shorts":
|
||||
youtube_shorts2(r, id);
|
||||
break;
|
||||
case "news_google":
|
||||
news_google(r, id);
|
||||
break;
|
||||
case "play_google":
|
||||
play_google(r, id);
|
||||
break;
|
||||
case "shopping":
|
||||
shopping(r, id);
|
||||
break;
|
||||
case "youtube":
|
||||
youtube(r, id);
|
||||
break;
|
||||
default:
|
||||
naver(r, id);
|
||||
break;
|
||||
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 },
|
||||
];
|
||||
|
||||
for (let index = 0; index < functoons.length; index++) {
|
||||
// const element = functoons[index];
|
||||
let name=functoons[index].name
|
||||
let funct=functoons[index].funct
|
||||
if(r==name){
|
||||
funct(r,id)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue