File size: 6,755 Bytes
2552b6a
 
 
 
 
 
 
 
e9b52f3
c615216
10f8fa5
 
50404c1
 
 
10f8fa5
 
 
ed89abd
 
 
18417a3
551ea8e
 
 
 
 
 
 
 
 
 
 
a6f84d2
 
 
 
 
 
 
 
 
 
 
46df9f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eee3fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c615216
c23b5e4
42f1aec
2552b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c615216
2552b6a
c615216
2552b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b8d9df
2552b6a
 
 
 
 
 
5b8d9df
2552b6a
 
 
 
 
 
 
 
 
 
 
 
 
6f6aa03
5b8d9df
2552b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const axios = require('axios');
const http = require('http');
const cron = require('node-cron');
const port = process.env.PORT || 7860;     
const moment = require('moment-timezone');

// 添加24小时访问的URL数组
const urls = [
               // 此处可备注名称,例如:H080

  
  'https://www.yahoo.com',             // 此处可备注名称,例如:glitch
'https://discovered-ajar-kilogram.glitch.me',
'https://butternut-purring-licorice.glitch.me',
'https://bubble-towering-freedom.glitch.me',
  






  
  
  // 添加更多24小时不间断访问的URL
];

// 添加在01:00至05:00暂停访问,其他时间正常访问的URL数组
function visitWebsites() {
  const websites = [




'https://unexpected-eager-dragon.glitch.me',
'https://marvelous-zippy-golf.glitch.me',
'https://chrome-bald-ship.glitch.me',
'https://midi-outstanding-flea.glitch.me',
'https://marvelous-plume-helium.glitch.me',
'https://instinctive-night-honey.glitch.me',
'https://evening-wheat-pecorino.glitch.me',
'https://kindhearted-colorful-alfalfa.glitch.me',
'https://early-lead-shampoo.glitch.me',
'https://indigo-hickory-ear.glitch.me',
'https://living-dented-rutabaga.glitch.me',
'https://luxurious-historical-cycle.glitch.me',
'https://leather-upbeat-gate.glitch.me',
'https://magenta-able-asparagus.glitch.me',
'https://checker-jumbled-helmet.glitch.me',
'https://climbing-transparent-event.glitch.me',
'https://lopsided-keen-celsius.glitch.me',
'https://nosy-reliable-echo.glitch.me',
'https://acidic-spiral-kryptops.glitch.me',
'https://endurable-prickly-busby.glitch.me',
'https://mint-young-angelfish.glitch.me',
'https://stirring-bronze-growth.glitch.me',
'https://abounding-roasted-hardware.glitch.me',
'https://telling-rhetorical-thunder.glitch.me',
'https://sincere-mellow-ketchup.glitch.me',
'https://jungle-sordid-sunfish.glitch.me',
'https://overjoyed-bedecked-flavor.glitch.me',
'https://boom-grass-vulcanodon.glitch.me',
'https://harvest-regal-puppy.glitch.me',
'https://silver-waiting-fin.glitch.me',
'https://diagnostic-apple-guide.glitch.me',
'https://relieved-climbing-chard.glitch.me',
'https://rhetorical-wobbly-asteroid.glitch.me',
'https://solar-rainy-ixia.glitch.me',
'https://irradiated-cooing-loan.glitch.me',
'https://valuable-slime-bream.glitch.me',
'https://flashy-basalt-jute.glitch.me',
'https://short-tree-broker.glitch.me',
'https://flicker-shiny-list.glitch.me',
'https://acute-silky-college.glitch.me',
'https://tough-voracious-dracopelta.glitch.me',
'https://destiny-typical-chard.glitch.me',
'https://sincere-rain-celsius.glitch.me',
'https://thunder-certain-viscount.glitch.me',
'https://slender-twisty-turnover.glitch.me',
'https://fearless-dolomite-macrame.glitch.me',
'https://invited-mysterious-puma.glitch.me',
'https://coherent-concise-mallet.glitch.me',
'https://waiting-obtainable-cloche.glitch.me',
'https://volcano-pumped-flag.glitch.me',
'https://burnt-six-cricket.glitch.me',
'https://cerulean-jelly-sailfish.glitch.me',
'https://crawling-thoughtful-bush.glitch.me',
'https://leeward-citrine-snap.glitch.me',
'https://capable-amenable-philosophy.glitch.me',
'https://husky-curved-jobaria.glitch.me',
'https://peppermint-rust-darkness.glitch.me',
'https://shadow-spectacular-balaur.glitch.me',
'https://chlorinated-lead-homburg.glitch.me',
'https://victorious-sand-turn.glitch.me',
'https://elegant-prong-tiara.glitch.me',
'https://efficient-bold-nautilus.glitch.me',
'https://tiny-crimson-seahorse.glitch.me',
'https://nervous-indigo-song.glitch.me',
'https://lavender-ember-zebra.glitch.me',
'https://cherry-weak-beaufort.glitch.me',
'https://lavish-rare-giganotosaurus.glitch.me',
'https://extreme-butter-mind.glitch.me',
'https://sage-road-cirrus.glitch.me',
'https://surf-peppermint-gallon.glitch.me',
'https://curvy-same-allium.glitch.me',
'https://scythe-canyon-whale.glitch.me',
'https://rose-funny-jasmine.glitch.me',
'https://pinto-hill-nyala.glitch.me',
'https://prairie-carnation-pincushion.glitch.me',
'https://sticky-wobbly-bagpipe.glitch.me',
'https://jolly-charmed-interest.glitch.me',
'https://discovered-ajar-kilogram.glitch.me',





    'https://www.google.com'         // 此处可备注名称,例如:Back4app,最后一个url后面没有逗号
    //添加更多的指定时间访问的URL
  ];

 // 遍历网页数组并发送请求
  websites.forEach(async (url) => {
    try {
      const response = await axios.get(url);
      console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Visited web successfully: ${url} - Status code: ${response.status}\n`);
    } catch (error) {
      console.error(`Error visiting ${url}: ${error.message}\n`);
    }
  });
}

// 检查并设置定时器
function checkAndSetTimer() {
  const currentMoment = moment().tz('Asia/Hong_Kong');
  const formattedTime = currentMoment.format('YYYY-MM-DD HH:mm:ss');
  if (currentMoment.hours() >= 1 && currentMoment.hours() < 5) {
    console.log(`Stop visit from 1:00 to 8:00 --- ${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}`);
    clearInterval(visitIntervalId); // 清除定时器
    const nextVisitTime = moment().tz('Asia/Hong_Kong').add(0, 'day').hours(8).minutes(0).seconds(0);
    const nextVisitInterval = nextVisitTime.diff(currentMoment);
    setTimeout(() => {
      startVisits();
    }, nextVisitInterval);
  } else {
    startVisits();
  }
}

let visitIntervalId; 
function startVisits() {
  clearInterval(visitIntervalId);
// visitWebsites();
  visitIntervalId = setInterval(() => {
    visitWebsites();
  }, 2 * 60 * 1000);   // 每2分钟执行一次访问
}

function runScript() {
  const runScriptIntervalId = setInterval(() => {
    //console.log('Running script');
    checkAndSetTimer();
  }, 2 * 60 * 1000); // 每2分钟检查一次
}
checkAndSetTimer();
runScript();

// 24小时不间断访问
async function scrapeAndLog(url) {
  try {
    const response = await axios.get(url);
    console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited Successfully: ${url} - Status code: ${response.status}\n`);
  } catch (error) {
    console.error(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}: Web visited Error: ${url}: ${error.message}\n`);
  }
}
// 每3分钟访问一次
cron.schedule('*/2 * * * *', () => {
  console.log('Running webpage access...');
  urls.forEach((url) => {
    scrapeAndLog(url);
  });
});

// 创建HTTP服务
const server = http.createServer((req, res) => {
  if (req.url === '/') {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, World!\n');
  } else {
    res.writeHead(404, {'Content-Type': 'text/plain'});
    res.end('Not Found\n');
  }
});

server.listen(port, () => {
  console.log(`Server is running on port:${port}`);
});