工匠放置小工具之1:事件提醒

工匠提醒

目前為 2025-09-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         工匠放置小工具之1:事件提醒
// @namespace    http://tampermonkey.net/
// @version      1.03
// @description  工匠提醒
// @author       Stella
// @match        https://idleartisan.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @license      CC-BY-NC-SA-4.0
// ==/UserScript==

(function() {
    'use strict';

    const COOLDOWN = 30 * 1000; // 30秒全局冷却
    let cooldownUntil = 0;

    // 默认配置
    const defaultConfig = {
        CB: true,       // 制作提醒
        Siege: true,    // 围攻提醒
        TS: true,       // 商船提醒
        M: true,        // 商人提醒
        GLOBAL: true,   // 全局开关
        IDLE: false     // 摸鱼模式
    };

    const config = {
        CB: GM_getValue('CB', defaultConfig.CB),
        Siege: GM_getValue('Siege', defaultConfig.Siege),
        TS: GM_getValue('TS', defaultConfig.TS),
        M: GM_getValue('M', defaultConfig.M),
        GLOBAL: GM_getValue('GLOBAL', defaultConfig.GLOBAL),
        IDLE: GM_getValue('IDLE', defaultConfig.IDLE)
    };

    // 创建浮动面板
    const panel = document.createElement('div');
    panel.style.position = 'fixed';
    panel.style.bottom = '20px';
    panel.style.right = '20px';
    panel.style.background = 'rgba(0,0,0,0.8)';
    panel.style.color = 'white';
    panel.style.padding = '12px';
    panel.style.borderRadius = '10px';
    panel.style.zIndex = 9999;
    panel.style.fontFamily = 'sans-serif';
    panel.style.fontSize = '14px';
    panel.style.boxShadow = '0 4px 12px rgba(0,0,0,0.5)';

    function createSwitch(labelText, key) {
        const container = document.createElement('div');
        container.style.marginBottom = '8px';
        container.style.display = 'flex';
        container.style.alignItems = 'center';
        container.style.justifyContent = 'space-between';

        const label = document.createElement('span');
        label.textContent = labelText;

        const switchContainer = document.createElement('div');
        switchContainer.style.width = '50px';
        switchContainer.style.height = '24px';
        switchContainer.style.background = config[key] ? '#4caf50' : '#ccc';
        switchContainer.style.borderRadius = '12px';
        switchContainer.style.position = 'relative';
        switchContainer.style.cursor = 'pointer';
        switchContainer.style.transition = 'background 0.3s';

        const knob = document.createElement('div');
        knob.style.width = '20px';
        knob.style.height = '20px';
        knob.style.background = '#fff';
        knob.style.borderRadius = '50%';
        knob.style.position = 'absolute';
        knob.style.top = '2px';
        knob.style.left = config[key] ? '28px' : '2px';
        knob.style.transition = 'left 0.3s';

        switchContainer.appendChild(knob);
        switchContainer.addEventListener('click', () => {
            config[key] = !config[key];
            GM_setValue(key, config[key]);
            switchContainer.style.background = config[key] ? '#4caf50' : '#ccc';
            knob.style.left = config[key] ? '28px' : '2px';
        });

        container.appendChild(label);
        container.appendChild(switchContainer);
        panel.appendChild(container);
    }

    // 按新顺序创建开关
    createSwitch('制作提醒', 'CB');
    createSwitch('围攻提醒', 'Siege');
    createSwitch('商船提醒', 'TS');
    createSwitch('商人提醒', 'M');
    panel.appendChild(document.createElement('hr')); // 分隔线
    createSwitch('全局开关', 'GLOBAL');
    createSwitch('摸鱼模式', 'IDLE');

    document.body.appendChild(panel);

    // 请求通知权限
    if (Notification.permission !== "granted") {
        Notification.requestPermission();
    }

    // 定时检测
    setInterval(() => {
        if (!config.GLOBAL) return; // 全局关闭,不提醒

        const now = Date.now();
        if (now < cooldownUntil) return;

        const title = document.title.trim();
        let notified = false;

        const notify = (msg) => {
            if (config.IDLE) msg = 'Windows 更新提醒';
            new Notification(config.IDLE ? 'Windows 更新提醒' : 'IdleArtisan 提醒', { body: msg, icon: "https://idleartisan.com/favicon.ico" });
            cooldownUntil = now + COOLDOWN;
            notified = true;
        };

        if (config.CB && title.includes("CB")) {
            notify("制作加成来了");
        } else if (config.Siege && title.includes("Siege")) {
            notify("准备 BOSS 战斗!");
        } else if (config.TS && title.includes("TS")) {
            notify("商船来了");
        } else if (config.M && title === "Idle Artisan - M") {
            notify("商人来了");
        }

    }, 10000);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址