-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathappsdoor.js
89 lines (76 loc) · 2.81 KB
/
appsdoor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const url = "https://gofans.cn/limited/ios";
const headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
};
if (typeof $task !== 'undefined') {
$task.fetch({ url: url, headers: headers }).then(response => {
handleResponse(response.body);
}, reason => {
console.log('获取应用信息失败:', reason.error);
$done();
});
} else if (typeof $httpClient !== 'undefined' && typeof $notification !== 'undefined') {
$httpClient.get({ url: url, headers: headers }, function (error, response, body) {
if (error) {
console.log('获取应用信息失败:', error);
$done();
return;
}
handleResponse(body);
});
} else if (typeof $request !== 'undefined' && typeof $notify !== 'undefined') {
$httpClient.get({ url: url, headers: headers }, function (error, response, body) {
if (error) {
console.log('获取应用信息失败:', error);
$done();
return;
}
handleResponse(body, $request.headers);
});
} else {
console.log('未知的脚本运行环境');
$done();
}
function handleResponse(body, requestHeaders) {
const appList = parseAppList(body);
const freeAppList = appList.filter(app => app.price === "Free");
let notificationContent = '';
const appCount = requestHeaders ? parseInt(requestHeaders['appCount']) || 8 : 8;
for (let i = 0; i < freeAppList.length && i < appCount; i++) {
const app = freeAppList[i];
const description = truncateDescription(app.description, 30);
notificationContent += `🆓${app.name}|原价¥${app.originalPrice}\n`;
}
if (typeof $notify !== 'undefined') {
$notify("AppStore限免APP", '', notificationContent);
} else if (typeof $notification !== 'undefined') {
$notification.post("AppStore限免APP", '', notificationContent);
} else {
console.log('未知的通知函数');
}
$done();
}
function parseAppList(html) {
const regex = /<div[^>]+class="column[^"]*"[^>]*>[\s\S]*?<strong[^>]+class="title[^"]*"[^>]*>(.*?)<\/strong>[\s\S]*?<b[^>]*>(.*?)<\/b>[\s\S]*?<div[^>]+class="price-original[^"]*"[^>]*>[^<]*<del[^>]*>(.*?)<\/del>[\s\S]*?<p[^>]+class="intro[^"]*"[^>]*>([\s\S]*?)<\/p>/g;
const appList = [];
let match;
while ((match = regex.exec(html)) !== null) {
const name = match[1];
const price = match[2];
const originalPrice = parseFloat(match[3]).toFixed(1);
const description = match[4].replace(/<.*?>/g, '').replace(/\n+/g, ' ').trim();
appList.push({
name: name,
price: price,
originalPrice: originalPrice,
description: description,
});
}
return appList;
}
function truncateDescription(description, maxLength) {
if (description.length > maxLength) {
return description.substring(0, maxLength) + '…';
}
return description;
}