【Komari】分享 Komari 监控面板的 Body

效果展示

使用方法

将下面代码修改好复制粘贴到 Komari 面板管理后台中的 [设置 - 站点 - 自定义Body] 中保存即可。

代码

  • 记得修改 /*自定义内容*//*YYYY-MM-DD*/ ,例: 千狐2025-09-13
  • 使用 卜算子 统计访客数量;
  • PS:点击 IP 可直接复制;
  • 代码可能有点冗余,有大佬懂的可以帮忙优化一下
  • 已让 ChatGPT 进行了代码优化,增加了文字阴影效果。
<body>
<div id="bodyContent" style="display:none;">
  <div class="top-info">
      <div class="info-item">
          <span class="info-label">/*自定义内容*/探针已运行:</span>
          <span id="runtimeValue" class="info-value">计算中...</span>
      </div>
      <div class="info-item">
          <span class="info-label">您的IP:</span>
          <span id="ipValue" class="info-value ip-value">获取中...</span>
          <span id="countryFlag" class="info-value" style="margin-left:5px;">🌐</span>
          <span id="busuanzi_container_site_pv" class="info-label">
              (您是本站👀第 <span id="busuanzi_value_site_pv"></span> 位鸡友)
          </span>
      </div>
  </div>

  <style>
  .top-info {
      position: fixed;
      top: 10px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 9999;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
      background: rgba(200, 200, 200, 0.15);
      padding: 8px 14px;
      border-radius: 14px;
      font-size: 14px;
      color: #eee;
      backdrop-filter: blur(8px);
      white-space: nowrap;
      text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
  }
  
  body { padding-top: 0; }
  .info-item { margin-right: 20px; }
  .info-label { color: #b388ff; }
  .info-value { color: #00e5ff; cursor: pointer; }
  </style>

  <script>
  const countryCodeToEmoji = code => {
      if (!code) return '🌐';
      return String.fromCodePoint(
          ...code.toUpperCase().split('').map(c => 0x1F1E6 + c.charCodeAt(0) - 65)
      );
  };

  function getVisitorIP() {
      const ipValue = document.getElementById('ipValue');
      const countryFlag = document.getElementById('countryFlag');
      const apis = [
          'https://ipapi.co/json/',
          'https://ipinfo.io/json',
          'https://api.myip.com',
          'https://api.ipify.org?format=json'
      ];

      (function tryAPI(i = 0) {
          if (i >= apis.length) {
              ipValue.textContent = '获取失败';
              countryFlag.textContent = '🌐';
              return;
          }
          fetch(apis[i])
              .then(r => r.json())
              .then(data => {
                  const ip = data.ip || data.query;
                  const countryCode = data.country || data.country_code;
                  if (!ip) throw new Error('无 IP');

                  ipValue.textContent = ip;
                  ipValue.title = '点击复制IP';
                  ipValue.onclick = () => {
                      navigator.clipboard.writeText(ip);
                      ipValue.textContent = '已复制!';
                      setTimeout(() => (ipValue.textContent = ip), 1500);
                  };

                  countryFlag.textContent = countryCodeToEmoji(countryCode);
              })
              .catch(() => tryAPI(i + 1));
      })();
  }

  function updateRuntime() {
      const start = new Date("/*YYYY-MM-DD*/T08:00:00");
      const runtime = document.getElementById('runtimeValue');
      function fmt() {
          const diff = Date.now() - start;
          const d = Math.floor(diff / 864e5);
          const h = Math.floor((diff % 864e5) / 36e5);
          const m = Math.floor((diff % 36e5) / 6e4);
          const s = Math.floor((diff % 6e4) / 1e3);
          runtime.textContent = `${d}天 ${h}小时 ${m}分钟 ${s}秒`;
      }
      fmt();
      setInterval(fmt, 1000);
  }

  document.addEventListener('DOMContentLoaded', () => {
      if (window.innerWidth <= 480) return;
      document.getElementById('bodyContent').style.display = 'block';
      getVisitorIP();
      updateRuntime();
  });
  </script>

  <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</div>
</body>
20 个赞

学习了

这是哪吒的皮肤?

更新了吗

虽然用不上,但是好看

学习了

我用的是 purcarte 这个主题,GitHub仓库地址:GitHub - Montia37/komari-theme-purcarte: 一个为 Komari 设计的磨砂玻璃风格主题
直接在管理后台中 [设置 - 主题管理] 将.zip文件上传应用就行了。
个人感觉起来像是哪吒 V0 和 V1 的结合 :joy:

1 个赞

你们好像对我的主题更感兴趣,放一张图给你们预览一下。 :smirking_face:

地址我就不放了,怕被打 :new_moon_face:

2 个赞

学习一下

好东西,拿走了

学习一下

还得是千户大佬

还得是你靠谱

非常好

不错的东西

谢谢千狐大佬,这个非常实用呢。

搞点小白喂饭教程

出点小白 喂饭教程 很多人不会搞反代

看不懂啊,佬

更新的