|
|
|
双击锁定/解锁 抢勋章的时候可以看时间,平时关闭就好了
- // ==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[beijingTime.getUTCDay()];
- 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 });
- }
- });
- })();
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|