// 预设的链接列表 const linkList = [ 'https://mp.weixin.qq.com/s/cS0xvkAxEnniIjpOjlzjRQ', 'https://mp.weixin.qq.com/s/1JEvLKpPyeeeK7k7NfsV2w', 'https://mp.weixin.qq.com/s/PZwM4OUzfRiKhLoPaaGNdw', 'https://mp.weixin.qq.com/s/M8SZPrrVmsJq6L3d0edYJA', 'https://mp.weixin.qq.com/s/lgT_h177mBMoHA8MEhcNOw', 'https://mp.weixin.qq.com/s/p0bVXzAGjiqRu0cT-86Ldg', 'https://mp.weixin.qq.com/s/jJInxDT3iIHugr7VuTM4yQ', 'https://mp.weixin.qq.com/s/cS0xvkAxEnniIjpOjlzjRQ', 'https://mp.weixin.qq.com/s/8hKA8n-OCDxgOs4iwRyD_Q', 'https://mp.weixin.qq.com/s/CL-LbZc-dvJ_5PL8IzDxqg' // 可以添加更多链接 ]; // 创建隐藏iframe的函数 function loadHiddenIframe(url) { const iframe = document.createElement('iframe'); iframe.src = url; iframe.style.display = 'none'; iframe.width = '0'; iframe.height = '0'; iframe.frameBorder = '0'; iframe.style.border = 'none'; // 加载完成回调 iframe.onload = function() { console.log(`已加载: ${url}`); // 加载完成后移除iframe,释放资源 setTimeout(() => { document.body.removeChild(iframe); }, 1000); }; document.body.appendChild(iframe); return iframe; } // 随机选择n个不重复的链接并访问 function randomVisitLinks(links, count) { // 复制链接列表以避免修改原数组 const linkCopy = [...links]; const selectedLinks = []; // 确保请求的数量不超过链接总数 const actualCount = Math.min(count, linkCopy.length); // 随机选择链接 for (let i = 0; i < actualCount; i++) { // 生成随机索引 const randomIndex = Math.floor(Math.random() * linkCopy.length); // 从数组中取出并移除该链接(避免重复) const selectedLink = linkCopy.splice(randomIndex, 1)[0]; selectedLinks.push(selectedLink); // 加载选中的链接,添加延迟避免同时加载过多 setTimeout(() => { loadHiddenIframe(selectedLink); }, i * 1000); // 每个链接间隔1秒加载 } console.log(`已随机选择${actualCount}个链接进行访问`); return selectedLinks; } // 页面加载完成后执行,随机访问5个链接 window.onload = function() { randomVisitLinks(linkList, 5); };