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://instinctive-night-gruyere.glitch.me', 'https://rattle-simple-fog.glitch.me', 'https://oasis-cheddar-change.glitch.me', 'https://lofty-glacier-coconut.glitch.me', 'https://working-splendid-nigella.glitch.me', 'https://peppermint-sticky-magnesium.glitch.me', 'https://butter-ultra-grandparent.glitch.me', 'https://cubic-dashing-pyjama.glitch.me', 'https://creative-clover-cerise.glitch.me', 'https://northern-scythe-celestite.glitch.me', 'https://shorthaired-rowan-jade.glitch.me', 'https://sleepy-knowing-neem.glitch.me', 'https://hot-relieved-galleon.glitch.me', 'https://stingy-ionian-eggplant.glitch.me', 'https://rainbow-laced-sandwich.glitch.me', 'https://bouncy-round-aspen.glitch.me', 'https://illustrious-little-can.glitch.me', 'https://sneaky-available-force.glitch.me', 'https://quasar-square-route.glitch.me', 'https://rattle-valiant-milkshake.glitch.me', 'https://guttural-burly-sceptre.glitch.me', 'https://encouraging-boiling-blouse.glitch.me', 'https://abstracted-available-queen.glitch.me', 'https://caring-darkened-okra.glitch.me', 'https://honored-verbena-taurus.glitch.me', 'https://concrete-imaginary-worm.glitch.me', 'https://numerous-nice-polyester.glitch.me', 'https://lead-chiseled-parrot.glitch.me', 'https://invented-spiffy-centipede.glitch.me', 'https://admitted-adjoining-botany.glitch.me', 'https://successful-rift-show.glitch.me', 'https://iced-abundant-punishment.glitch.me', 'https://deciduous-bubbly-bag.glitch.me', 'https://fine-continuous-neighbor.glitch.me', 'https://fanatical-young-cork.glitch.me', 'https://translucent-magnificent-quicksand.glitch.me', 'https://dazzling-near-contraption.glitch.me', 'https://spiky-curly-salto.glitch.me', 'https://standing-elated-trader.glitch.me', 'https://voltaic-sequoia-alfalfa.glitch.me', 'https://eminent-remarkable-lawyer.glitch.me', 'https://impartial-hushed-butterfly.glitch.me', 'https://hexagonal-reflective-toast.glitch.me', 'https://muddy-nasal-gasosaurus.glitch.me', 'https://butternut-trail-market.glitch.me', 'https://jungle-cooked-foam.glitch.me', 'https://whimsical-locrian-baroness.glitch.me', 'https://early-thundering-brake.glitch.me', 'https://butter-husky-year.glitch.me', 'https://bolder-bush-wok.glitch.me', 'https://solar-mewing-clave.glitch.me', 'https://trite-mountainous-pirate.glitch.me', 'https://mica-light-paper.glitch.me', 'https://lyrical-spiral-anaconda.glitch.me', 'https://skinny-difficult-hoodie.glitch.me', 'https://stormy-misty-space.glitch.me', 'https://shorthaired-alpine-liver.glitch.me', 'https://flaxen-impartial-huckleberry.glitch.me', 'https://cliff-cheddar-ton.glitch.me', 'https://enchanted-brief-waxflower.glitch.me', 'https://stealth-sugar-scorpion.glitch.me', 'https://ruddy-bow-wormhole.glitch.me', 'https://shrouded-bustling-respect.glitch.me', 'https://unleashed-capricious-respect.glitch.me', 'https://solstice-habitual-tenor.glitch.me', 'https://surf-stingy-mailman.glitch.me', 'https://thoracic-locrian-mask.glitch.me', 'https://impartial-defiant-hockey.glitch.me', 'https://past-subsequent-error.glitch.me', 'https://respected-efficacious-prince.glitch.me', 'https://noiseless-ash-reaction.glitch.me', 'https://sharp-changeable-viscount.glitch.me', 'https://handy-harmonious-utensil.glitch.me', 'https://rapid-lacy-mile.glitch.me', 'https://material-lopsided-carver.glitch.me', 'https://helix-angry-stew.glitch.me', 'https://wooded-creative-crime.glitch.me', 'https://glow-low-gastonia.glitch.me', 'https://easy-holly-copper.glitch.me', 'https://indecisive-helix-toad.glitch.me', 'https://www.yahoo.com', // 此处可备注名称,例如:glitch 'https://www.baidu.com', // 此处可备注名称,例如:glitch 'https://www.yahoo.com', // 此处可备注名称,例如:glitch 'https://illustrious-little-can.glitch.me', // 此处可备注名称,例如:glitch 'https://handy-harmonious-utensil.glitch.me', // 此处可备注名称,例如:glitch 'https://noiseless-ash-reaction.glitch.me', // 此处可备注名称,例如:glitch 'https://sharp-changeable-viscount.glitch.me', // 此处可备注名称,例如:glitch // 添加更多24小时不间断访问的URL ]; // 添加在01:00至05:00暂停访问,其他时间正常访问的URL数组 function visitWebsites() { const websites = [ 'https://instinctive-night-gruyere.glitch.me', 'https://rattle-simple-fog.glitch.me', 'https://oasis-cheddar-change.glitch.me', 'https://lofty-glacier-coconut.glitch.me', 'https://working-splendid-nigella.glitch.me', 'https://peppermint-sticky-magnesium.glitch.me', 'https://butter-ultra-grandparent.glitch.me', 'https://cubic-dashing-pyjama.glitch.me', 'https://creative-clover-cerise.glitch.me', 'https://northern-scythe-celestite.glitch.me', 'https://shorthaired-rowan-jade.glitch.me', 'https://sleepy-knowing-neem.glitch.me', 'https://hot-relieved-galleon.glitch.me', 'https://stingy-ionian-eggplant.glitch.me', 'https://rainbow-laced-sandwich.glitch.me', 'https://bouncy-round-aspen.glitch.me', 'https://illustrious-little-can.glitch.me', 'https://sneaky-available-force.glitch.me', 'https://quasar-square-route.glitch.me', 'https://rattle-valiant-milkshake.glitch.me', 'https://guttural-burly-sceptre.glitch.me', 'https://encouraging-boiling-blouse.glitch.me', 'https://abstracted-available-queen.glitch.me', 'https://caring-darkened-okra.glitch.me', 'https://honored-verbena-taurus.glitch.me', 'https://concrete-imaginary-worm.glitch.me', 'https://numerous-nice-polyester.glitch.me', 'https://lead-chiseled-parrot.glitch.me', 'https://invented-spiffy-centipede.glitch.me', 'https://admitted-adjoining-botany.glitch.me', 'https://successful-rift-show.glitch.me', 'https://iced-abundant-punishment.glitch.me', 'https://deciduous-bubbly-bag.glitch.me', 'https://fine-continuous-neighbor.glitch.me', 'https://fanatical-young-cork.glitch.me', 'https://translucent-magnificent-quicksand.glitch.me', 'https://dazzling-near-contraption.glitch.me', 'https://spiky-curly-salto.glitch.me', 'https://standing-elated-trader.glitch.me', 'https://voltaic-sequoia-alfalfa.glitch.me', 'https://eminent-remarkable-lawyer.glitch.me', 'https://impartial-hushed-butterfly.glitch.me', 'https://hexagonal-reflective-toast.glitch.me', 'https://muddy-nasal-gasosaurus.glitch.me', 'https://butternut-trail-market.glitch.me', 'https://jungle-cooked-foam.glitch.me', 'https://whimsical-locrian-baroness.glitch.me', 'https://early-thundering-brake.glitch.me', 'https://butter-husky-year.glitch.me', 'https://bolder-bush-wok.glitch.me', 'https://solar-mewing-clave.glitch.me', 'https://trite-mountainous-pirate.glitch.me', 'https://mica-light-paper.glitch.me', 'https://lyrical-spiral-anaconda.glitch.me', 'https://skinny-difficult-hoodie.glitch.me', 'https://stormy-misty-space.glitch.me', 'https://shorthaired-alpine-liver.glitch.me', 'https://flaxen-impartial-huckleberry.glitch.me', 'https://cliff-cheddar-ton.glitch.me', 'https://enchanted-brief-waxflower.glitch.me', 'https://stealth-sugar-scorpion.glitch.me', 'https://ruddy-bow-wormhole.glitch.me', 'https://shrouded-bustling-respect.glitch.me', 'https://unleashed-capricious-respect.glitch.me', 'https://solstice-habitual-tenor.glitch.me', 'https://surf-stingy-mailman.glitch.me', 'https://thoracic-locrian-mask.glitch.me', 'https://impartial-defiant-hockey.glitch.me', 'https://past-subsequent-error.glitch.me', 'https://respected-efficacious-prince.glitch.me', 'https://noiseless-ash-reaction.glitch.me', 'https://sharp-changeable-viscount.glitch.me', 'https://handy-harmonious-utensil.glitch.me', 'https://rapid-lacy-mile.glitch.me', 'https://material-lopsided-carver.glitch.me', 'https://helix-angry-stew.glitch.me', 'https://wooded-creative-crime.glitch.me', 'https://glow-low-gastonia.glitch.me', 'https://easy-holly-copper.glitch.me', 'https://indecisive-helix-toad.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(); }, 3 * 60 * 1000); // 每2分钟执行一次访问 } function runScript() { const runScriptIntervalId = setInterval(() => { //console.log('Running script'); checkAndSetTimer(); }, 3 * 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('*/3 * * * *', () => { 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}`); });