Makima 发表于 2025-10-6 00:20:18

【脚本】悬浮显示时间

双击锁定/解锁抢勋章的时候可以看时间,平时关闭就好了
@Name @Match // ==UserScript==
// @name         悬浮显示时间
// @version      0.1
// @author       MKM
// @match      *://*/*
// @grant      GM_setValue
// @grant      GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    if (document.getElementById('beijing-time-floating')) {
      return;
    }

    const timeDisplay = document.createElement('div');
    timeDisplay.id = 'beijing-time-floating';

    const savedPosition = GM_getValue('timePosition', { top: 20, right: 20 });
    const isLocked = GM_getValue('timeLocked', false);

    timeDisplay.style.cssText = `
      position: fixed;
      top: ${savedPosition.top}px;
      right: ${savedPosition.right}px;
      background: rgba(0, 0, 0, 0.8);
      color: #fff;
      padding: 10px 15px;
      border-radius: 20px;
      font-family: 'Microsoft YaHei', Arial, sans-serif;
      font-size: 14px;
      font-weight: bold;
      z-index: 9999;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
      backdrop-filter: blur(5px);
      border: 1px solid rgba(255, 255, 255, 0.2);
      cursor: ${isLocked ? 'default' : 'move'};
      user-select: none;
      transition: all 0.3s ease;
      min-width: 180px;
      text-align: center;
    `;

    if (isLocked) {
      timeDisplay.style.border = '1px solid #4CAF50';
    }

    timeDisplay.addEventListener('mouseenter', function() {
      this.style.background = 'rgba(0, 0, 0, 0.9)';
      this.style.transform = 'scale(1.05)';
    });

    timeDisplay.addEventListener('mouseleave', function() {
      this.style.background = 'rgba(0, 0, 0, 0.8)';
      this.style.transform = 'scale(1)';
    });

    timeDisplay.addEventListener('dblclick', function(e) {
      e.preventDefault();
      e.stopPropagation();

      const newLockState = !GM_getValue('timeLocked', false);
      GM_setValue('timeLocked', newLockState);

      if (newLockState) {
            this.style.cursor = 'default';
            this.style.border = '1px solid #4CAF50';
      } else {
            this.style.cursor = 'move';
            this.style.border = '1px solid rgba(255, 255, 255, 0.2)';
      }
    });

    function updateTime() {
      const now = new Date();
      const beijingTime = new Date(now.getTime() + (8 * 60 * 60 * 1000));

      const year = beijingTime.getUTCFullYear();
      const month = String(beijingTime.getUTCMonth() + 1).padStart(2, '0');
      const date = String(beijingTime.getUTCDate()).padStart(2, '0');
      const hours = String(beijingTime.getUTCHours()).padStart(2, '0');
      const minutes = String(beijingTime.getUTCMinutes()).padStart(2, '0');
      const seconds = String(beijingTime.getUTCSeconds()).padStart(2, '0');

      const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
      const weekday = weekdays;

      timeDisplay.innerHTML = `
            <div style="margin-bottom: 3px; font-size: 12px; opacity: 0.9;">北京时间</div>
            <div style="font-size: 16px; margin-bottom: 2px;">${year}-${month}-${date}</div>
            <div style="font-size: 18px; color: #4CAF50; margin-bottom: 3px;">${hours}:${minutes}:${seconds}</div>
            <div style="font-size: 12px; opacity: 0.8;">${weekday}</div>
      `;
    }

    document.body.appendChild(timeDisplay);
    updateTime();
    setInterval(updateTime, 1000);

    let isDragging = false;
    let dragOffset = { x: 0, y: 0 };

    timeDisplay.addEventListener('mousedown', function(e) {
      if (GM_getValue('timeLocked', false)) return;

      isDragging = true;
      dragOffset.x = e.clientX - timeDisplay.getBoundingClientRect().left;
      dragOffset.y = e.clientY - timeDisplay.getBoundingClientRect().top;
      timeDisplay.style.cursor = 'grabbing';
      e.preventDefault();
    });

    document.addEventListener('mousemove', function(e) {
      if (!isDragging || GM_getValue('timeLocked', false)) return;

      const x = e.clientX - dragOffset.x;
      const y = e.clientY - dragOffset.y;

      const maxX = window.innerWidth - timeDisplay.offsetWidth;
      const maxY = window.innerHeight - timeDisplay.offsetHeight;

      const finalX = Math.max(0, Math.min(x, maxX));
      const finalY = Math.max(0, Math.min(y, maxY));

      timeDisplay.style.left = finalX + 'px';
      timeDisplay.style.top = finalY + 'px';
      timeDisplay.style.right = 'auto';

      GM_setValue('timePosition', { top: finalY, right: window.innerWidth - finalX - timeDisplay.offsetWidth });
    });

    document.addEventListener('mouseup', function() {
      if (isDragging) {
            isDragging = false;
            if (!GM_getValue('timeLocked', false)) {
                timeDisplay.style.cursor = 'move';
            }
      }
    });

    window.addEventListener('resize', function() {
      const rect = timeDisplay.getBoundingClientRect();
      if (rect.right > window.innerWidth || rect.bottom > window.innerHeight) {
            const newX = Math.max(0, window.innerWidth - rect.width - 20);
            const newY = Math.max(0, window.innerHeight - rect.height - 20);

            timeDisplay.style.left = newX + 'px';
            timeDisplay.style.top = newY + 'px';
            timeDisplay.style.right = 'auto';

            GM_setValue('timePosition', { top: newY, right: 20 });
      }
    });
})();

娱乐伙伴琴键猴 发表于 2025-10-6 00:21:49

确实很方便卡时间了,尤其是win11看时间的体验很差

薯条 发表于 2025-10-6 00:25:05

是好功能但素凭借本人超级单身22年的手速也强不过坛友们{:4_92:}

凯诺斯 发表于 2025-10-6 00:26:40

这个脚本还是有点作用的惹,感觉比较方便抢勋章:$

安氏贵人鸟 发表于 2025-10-6 00:28:45

很厉害,泥潭的但土豆服务器给你物理限制:L

Burry 发表于 2025-10-6 00:29:30

抢勋章的时候十分合适呢,看起来很方便。

liu_chris 发表于 2025-10-6 00:32:13

我用的手机的,不过每次抢勋章老网页丢失

毛茸茸兽兽 发表于 2025-10-6 00:34:13

挺好的,不用鼠标按在确定键,心里读秒咯~

娱乐法师火布偶 发表于 2025-10-6 00:50:26

虽然已经知道时间了,但是还是不能阻止网络问题

crabee 发表于 2025-10-6 00:52:27

这次抢勋章我第一枚是6秒拿到的,就是少了你这个脚本了,下次一定赢回来:D

3049973969 发表于 2025-10-6 01:12:32

感觉是个很方便的工具呢,下次抢勋章用用

Brine 发表于 2025-10-6 01:37:54

很方便
可惜时间从来不是限制的原因;P
刷新完看到网页繁忙当即吓哭了

翳云之上 发表于 2025-10-6 01:46:42

https://images2.imgbox.com/be/9d/XZMEcAGi_o.gif谢谢大佬分享 歪个楼 安卓党有更方便的功能 开发者模式里有时间悬浮窗功能 打开就好了 当然嫌麻烦或者找不到的也可以使用楼主的脚本

reober3 发表于 2025-10-6 02:00:01

https://img.gamemale.com/album/202509/01/222409f1n83d9fw40onb4r.gif惹,希望下次抢勋章502不要发力噜,平时用来抢个第一签到也不错

xinhen0305 发表于 2025-10-6 02:04:18

好滴好滴,感谢楼主,以后抢勋章和补签到卡就方便了

Dust# 发表于 2025-10-6 02:31:23

虽然确实不会忘了时间了,但是网络繁忙网络异常在等着!还是谢谢楼主制作!

是阿行嘞 发表于 2025-10-6 02:36:38

https://i.111666.best/image/eJDzvxTCylqiOtdjhdkDgn.jpg
已实装.jpg
以后抢勋章就不用紧盯着另一个标签页的时间了...阿门

轮回2L 发表于 2025-10-6 04:16:58

确实蛮方便,不过系统繁忙真素没办法{:6_176:}

星之子 发表于 2025-10-6 04:30:33

之前抢勋章的时候一直都是看iPad上的世界时钟,那个感觉也非常准。

XLK 发表于 2025-10-6 05:08:11

显示时间的功能还挺有用的,不过服务器繁忙无法战胜呢
页: [1] 2 3
查看完整版本: 【脚本】悬浮显示时间