// ==UserScript== // @name weiyong222 // @namespace http://tampermonkey.net/ // @version 2025-07-25 // @description 自动跟进系统 // @author You // @match http://call.changmujiayu.cn/web/2024/* // @match https://call.changmujiayu.cn/web/2024/* // @grant none // ==/UserScript== (function() { 'use strict'; //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ // 自动关闭提示系统 //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ const Toast = { show(msg, type = 'info') { const toast = document.createElement('div'); toast.textContent = msg; toast.style.cssText = ` position: fixed; top: 20px; right: 20px; padding: 12px 24px; background: ${type === 'error' ? '#ff4444' : '#4CAF50'}; color: white; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.2); z-index: 99999; opacity: 0; transform: translateY(-20px); transition: all 0.3s ease; `; document.body.appendChild(toast); setTimeout(() => { toast.style.opacity = '1'; toast.style.transform = 'translateY(0)'; }, 10); setTimeout(() => { toast.style.opacity = '0'; setTimeout(() => toast.remove(), 300); }, 3000); } }; //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ // 日期自动设置模块 //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ const DateAutoSetter = { init() { this.retries = 0; this.initialized = false; this.observer = new MutationObserver(this.check.bind(this)); this.start(); }, start() { if(document.readyState === 'complete') { this.check(); } else { window.addEventListener('load', () => this.check()); document.addEventListener('DOMContentLoaded', () => this.check()); } this.observer.observe(document.body, { childList: true, subtree: true }); }, check() { const date1 = document.getElementById('date1'); const date2 = document.getElementById('date2'); if(date1 && date2 && !this.initialized) { this.initialized = true; this.setDates(date1, date2); this.triggerSearch(); this.observer.disconnect(); this.startAutoRefresh(); } else if(this.retries++ < 15) { setTimeout(() => this.check(), 300); } }, setDates(date1, date2) { const today = new Date(); const pad = n => String(n).padStart(2,'0'); const dateStr = `${today.getFullYear()}-${pad(today.getMonth()+1)}-${pad(today.getDate())}`; [date1, date2].forEach(el => { el.value = dateStr; ['input', 'change', 'blur'].forEach(event => { el.dispatchEvent(new Event(event, { bubbles: true })); }); }); }, triggerSearch() { setTimeout(() => { if(typeof load_search_info === 'function') { load_search_info(); } }, 800); }, startAutoRefresh() { const REFRESH_INTERVAL = 300; // 30秒刷新一次 window.timerSearchInfo = setInterval(() => { load_search_info(); console.log("自动刷新执行"); }, REFRESH_INTERVAL); Toast.show(`自动刷新已启动(间隔${REFRESH_INTERVAL/1000}秒)`); } }; //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ // 业务逻辑函数 //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ function load_search_info() { o["tel"] = document.getElementById("phone2").value; o["channel"] = document.getElementById("pkey_id").value; o["mer_id"] = document.getElementById("mer_id").value; o["dat1"] = document.getElementById("date1").value; o["dat2"] = document.getElementById("date2").value; o["hasName"] = document.getElementById("hasName").value; o["page"] = 1; o["user_type"] = 1; $.ajax({ type: "POST", url: "api/high_seas_list.php?ak=" + getQueryString('ak'), data: dess(o), success: function(data0) { const data = desj(data0); data.arr.forEach(item => { if(time_diff(item.reg_tim)) { // 默认检查60秒内数据 console.log("发现新客户:", item.tel); follow_info(item.tel, item.id); } }); }, error: () => Toast.show("数据加载失败", 'error') }); } function follow_info(tel, id) { $.ajax({ type: "GET", url: `api/begin_one.php?tel=${tel}&id=${id}&ak=${getQueryString("ak")}`, success: function(data) { o = data; if (o.status) { $(`.status_${tel}`).html("跟进中"); $(`.caller_${tel}`).html(o.nickname); $(`.tel1_${tel}`) .after(`反馈跟进结果`) .remove(); } Toast.show(o.message, o.status ? 'info' : 'error'); if (o.status === 1) { window.location = `private_list.php?ak=${getQueryString('ak')}`; } }, error: () => Toast.show("跟进请求失败", 'error') }); } function time_diff(s) { // 简化为固定检查60秒内 if (!s) return false; try { const [datePart, timePart] = s.split(' '); const [year, month, day] = datePart.split('-').map(Number); const [hours, minutes, seconds] = timePart.split(':').map(Number); const timer = new Date(year, month-1, day, hours, minutes, seconds); return (new Date() - timer) < 60000; // 60秒内 } catch(e) { console.error("时间解析错误:", e); return false; } } //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ // 初始化 //▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ DateAutoSetter.init(); })();