Upload 4 files
Browse files- Dockerfile +12 -0
- index.html +52 -0
- index.js +116 -0
- package.json +21 -0
Dockerfile
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY . .
|
6 |
+
|
7 |
+
EXPOSE 7860
|
8 |
+
|
9 |
+
RUN apt update -y &&\
|
10 |
+
npm install
|
11 |
+
|
12 |
+
CMD ["node", "index.js"]
|
index.html
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>将 进 酒</title>
|
6 |
+
<style>
|
7 |
+
body {
|
8 |
+
font-family: Arial, sans-serif;
|
9 |
+
text-align: center;
|
10 |
+
background-color: #f0f0f0;
|
11 |
+
}
|
12 |
+
header {
|
13 |
+
background-color: #4a4a4a;
|
14 |
+
color: #fff;
|
15 |
+
padding: 2px;
|
16 |
+
}
|
17 |
+
h1 {
|
18 |
+
font-size: 36px;
|
19 |
+
}
|
20 |
+
#content {
|
21 |
+
max-width: 800px;
|
22 |
+
margin: 0 auto;
|
23 |
+
padding: 20px;
|
24 |
+
background-color: #fff;
|
25 |
+
border-radius: 5px;
|
26 |
+
}
|
27 |
+
p {
|
28 |
+
font-size: 18px;
|
29 |
+
line-height: 1.5;
|
30 |
+
}
|
31 |
+
</style>
|
32 |
+
</head>
|
33 |
+
<body>
|
34 |
+
<header>
|
35 |
+
<h1>将进酒</h1>
|
36 |
+
</header>
|
37 |
+
<div id="content">
|
38 |
+
<p>君不见,黄河之水天上来,奔流到海不复回。</p>
|
39 |
+
<p>君不见,高堂明镜悲白发,朝如青丝暮成雪。</p>
|
40 |
+
<p>人生得意须尽欢,莫使金樽空对月。</p>
|
41 |
+
<p>天生我材必有用,千金散尽还复来。</p>
|
42 |
+
<p>烹羊宰牛且为乐,会须一饮三百杯。</p>
|
43 |
+
<p>岑夫子,丹丘生,将进酒,杯莫停。</p>
|
44 |
+
<p>与君歌一曲,请君为我倾耳听。</p>
|
45 |
+
<p>钟鼓馔玉不足贵,但愿长醉不愿醒。</p>
|
46 |
+
<p>古来圣贤皆寂寞,惟有饮者留其名。</p>
|
47 |
+
<p>陈王昔时宴平乐,斗酒十千恣欢谑。</p>
|
48 |
+
<p>主人何为言少钱,径须沽取对君酌。</p>
|
49 |
+
<p>五花马、千金裘,呼儿将出换美酒,与尔同销万古愁。</p>
|
50 |
+
</div>
|
51 |
+
</body>
|
52 |
+
</html>
|
index.js
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const axios = require('axios');
|
2 |
+
const http = require('http');
|
3 |
+
const path = require('path');
|
4 |
+
const fs = require('fs');
|
5 |
+
const cron = require('node-cron');
|
6 |
+
const port = process.env.PORT || 7860;
|
7 |
+
const moment = require('moment-timezone');
|
8 |
+
|
9 |
+
// 添加24小时访问的URL数组
|
10 |
+
const urls = [
|
11 |
+
'https://www.baidu.com', // 此处可备注名称,例如:glitch
|
12 |
+
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
|
13 |
+
'https://www.baidu.com', // 此处可备注名称,例如:glitch
|
14 |
+
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
|
15 |
+
'https://www.baidu.com', // 此处可备注名称,例如:glitch
|
16 |
+
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
|
17 |
+
'https://www.baidu.com', // 此处可备注名称,例如:glitch
|
18 |
+
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
|
19 |
+
// 添加更多24小时不间断访问的URL
|
20 |
+
];
|
21 |
+
|
22 |
+
// 添加在01:00至05:00暂停访问,其他时间正常访问的URL数组
|
23 |
+
function visitWebsites() {
|
24 |
+
const websites = [
|
25 |
+
'https://www.google.com', // 此处可备注名称,例如:Back4app
|
26 |
+
'https://www.google.com', // 此处可备注名称,例如:Back4app
|
27 |
+
'https://www.google.com', // 此处可备注名称,例如:Back4app
|
28 |
+
'https://www.google.com' // 此处可备注名称,例如:Back4app,最后一个url后面没有逗号
|
29 |
+
//添加更多的指定时间访问的URL
|
30 |
+
];
|
31 |
+
|
32 |
+
// 遍历网页数组并发送请求
|
33 |
+
websites.forEach(async (url) => {
|
34 |
+
try {
|
35 |
+
const response = await axios.get(url);
|
36 |
+
console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Visited web successfully: ${url} - Status code: ${response.status}\n`);
|
37 |
+
} catch (error) {
|
38 |
+
console.error(`Error visiting ${url}: ${error.message}\n`);
|
39 |
+
}
|
40 |
+
});
|
41 |
+
}
|
42 |
+
|
43 |
+
// 检查并设置定时器
|
44 |
+
function checkAndSetTimer() {
|
45 |
+
const currentMoment = moment().tz('Asia/Hong_Kong');
|
46 |
+
const formattedTime = currentMoment.format('YYYY-MM-DD HH:mm:ss');
|
47 |
+
if (currentMoment.hours() >= 1 && currentMoment.hours() < 5) {
|
48 |
+
console.log(`Stop visit from 1:00 to 5:00 --- ${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}`);
|
49 |
+
clearInterval(visitIntervalId); // 清除定时器
|
50 |
+
const nextVisitTime = moment().tz('Asia/Hong_Kong').add(0, 'day').hours(5).minutes(0).seconds(0);
|
51 |
+
const nextVisitInterval = nextVisitTime.diff(currentMoment);
|
52 |
+
setTimeout(() => {
|
53 |
+
startVisits();
|
54 |
+
}, nextVisitInterval);
|
55 |
+
} else {
|
56 |
+
startVisits();
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
let visitIntervalId;
|
61 |
+
function startVisits() {
|
62 |
+
clearInterval(visitIntervalId);
|
63 |
+
// visitWebsites();
|
64 |
+
visitIntervalId = setInterval(() => {
|
65 |
+
visitWebsites();
|
66 |
+
}, 2 * 60 * 1000); // 每2分钟执行一次访问
|
67 |
+
}
|
68 |
+
|
69 |
+
function runScript() {
|
70 |
+
const runScriptIntervalId = setInterval(() => {
|
71 |
+
//console.log('Running script');
|
72 |
+
checkAndSetTimer();
|
73 |
+
}, 2 * 60 * 1000); // 每2分钟检查一次
|
74 |
+
}
|
75 |
+
checkAndSetTimer();
|
76 |
+
runScript();
|
77 |
+
|
78 |
+
// 24小时不间断访问
|
79 |
+
async function scrapeAndLog(url) {
|
80 |
+
try {
|
81 |
+
const response = await axios.get(url);
|
82 |
+
console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited Successfully: ${url} - Status code: ${response.status}\n`);
|
83 |
+
} catch (error) {
|
84 |
+
console.error(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited Error: ${url}: ${error.message}\n`);
|
85 |
+
}
|
86 |
+
}
|
87 |
+
// 每2分钟访问一次
|
88 |
+
cron.schedule('*/2 * * * *', () => {
|
89 |
+
console.log('Running webpage access...');
|
90 |
+
urls.forEach((url) => {
|
91 |
+
scrapeAndLog(url);
|
92 |
+
});
|
93 |
+
});
|
94 |
+
|
95 |
+
// 创建HTTP服务
|
96 |
+
const server = http.createServer((req, res) => {
|
97 |
+
if (req.url === '/') {
|
98 |
+
const filePath = path.join(__dirname, 'index.html');
|
99 |
+
fs.readFile(filePath, (err, data) => {
|
100 |
+
if (err) {
|
101 |
+
res.writeHead(500);
|
102 |
+
res.end('Error loading index.html');
|
103 |
+
} else {
|
104 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
105 |
+
res.end(data);
|
106 |
+
}
|
107 |
+
});
|
108 |
+
} else {
|
109 |
+
res.writeHead(404);
|
110 |
+
res.end('Not Found');
|
111 |
+
}
|
112 |
+
});
|
113 |
+
|
114 |
+
server.listen(port, () => {
|
115 |
+
console.log(`Server is running on port ${port}`);
|
116 |
+
});
|
package.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "keep-online",
|
3 |
+
"version": "2.0.0",
|
4 |
+
"description": "Auto-keep-online",
|
5 |
+
"main": "index.js",
|
6 |
+
"author": "",
|
7 |
+
"repository": "",
|
8 |
+
"license": "MIT",
|
9 |
+
"private": false,
|
10 |
+
"scripts": {
|
11 |
+
"start": "node index.js"
|
12 |
+
},
|
13 |
+
"dependencies": {
|
14 |
+
"axios": "^1.6.2",
|
15 |
+
"node-cron": "^2.0.1",
|
16 |
+
"moment-timezone": "latest"
|
17 |
+
},
|
18 |
+
"engines": {
|
19 |
+
"node": ">=14"
|
20 |
+
}
|
21 |
+
}
|