// ==UserScript== // @name AGJ 资源面板 + 页面切换也拦死exit // @namespace http://tampermonkey.net/ // @version 9.0 // @description 拦截页面切换/关闭/刷新的exit请求,绝对发不出去 // @author assistant // @match *://718zf.xyz/agj.php // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 资源图标 const RES_MAP = { 1: '🌲木材', 2: '⚙️钢铁', 3: '🌾粮食', 4: '💎宝石' }; // 全局 let captured = false; let requestTemplate = null; let intervalTimer = null; let currentResources = {1:0,2:0,3:0,4:0}; // ============================================== // 【终极拦截】exit 请求,页面切换/关闭/刷新都拦死 // ============================================== function blockAllExit() { // 拦截 XHR const _open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(m, url) { if (String(url).includes('agj_api.php?action=exit')) { console.log('🚫 拦截XHR exit'); this.send = () => {}; return; } return _open.apply(this, arguments); }; // 拦截 Fetch if (window.fetch) { const _fetch = window.fetch; window.fetch = function(input, init) { const u = String(input || ''); if (u.includes('agj_api.php?action=exit')) { console.log('🚫 拦截Fetch exit'); return new Promise(()=>{}); } return _fetch.call(this, input, init); }; } // 拦截 页面卸载/切换 发送的请求(关键!) window.addEventListener('beforeunload', (e) => { e.stopImmediatePropagation(); e.preventDefault(); }, true); // 覆盖 sendBeacon(页面关闭专用发送接口) if (navigator.sendBeacon) { const _beacon = navigator.sendBeacon; navigator.sendBeacon = function(url) { if (url.includes('agj_api.php?action=exit')) { console.log('🚫 拦截Beacon exit'); return false; } return _beacon.call(this, url); }; } } // 启动拦截(页面一开始就启用) blockAllExit(); // ============================================== // 面板 UI // ============================================== function createPanel() { const panel = document.createElement('div'); panel.style.cssText = ` position:fixed; top:10px; right:10px; width:170px; background:#fff; border-radius:6px; padding:6px; box-shadow:0 0 5px rgba(0,0,0,0.15); z-index:999999; font-size:12px; color:#222; `; const title = document.createElement('div'); title.textContent = 'AGJ 当前资源'; title.style.cssText = 'font-weight:bold;text-align:center;margin-bottom:5px;'; panel.appendChild(title); const line = document.createElement('div'); line.style.cssText = 'display:flex;gap:4px;align-items:center;margin-bottom:6px;'; line.innerHTML = '每秒:'; const input = document.createElement('input'); input.type = 'number'; input.value = 2; input.style.cssText = 'width:40px;padding:2px;font-size:12px;'; const btn = document.createElement('button'); btn.textContent = '启动'; btn.style.cssText = 'padding:2px 4px;font-size:12px;'; line.append(input, btn); panel.appendChild(line); const show = document.createElement('div'); show.style.lineHeight = '1.4'; show.id = 'resDisplay'; panel.appendChild(show); document.body.appendChild(panel); btn.onclick = () => { if (!requestTemplate) return alert('先触发一次游戏请求!'); clearInterval(intervalTimer); const ps = parseFloat(input.value) || 1; intervalTimer = setInterval(doRequest, 1000/ps); btn.textContent = '运行中'; }; window.resDisplay = show; } // 渲染 function render() { window.resDisplay.innerHTML = ` ${RES_MAP[1]}:${currentResources[1]}
${RES_MAP[2]}:${currentResources[2]}
${RES_MAP[3]}:${currentResources[3]}
${RES_MAP[4]}:${currentResources[4]} `; } // 请求 function doRequest() { const xhr = new XMLHttpRequest(); xhr.open(requestTemplate.method, requestTemplate.url, true); Object.entries(requestTemplate.headers).forEach(([k,v])=>xhr.setRequestHeader(k,v)); xhr.onload = () => { try { const res = JSON.parse(xhr.responseText); if (res.resources) currentResources = res.resources; } catch(e){} render(); }; xhr.send(requestTemplate.body); } // 捕获第一次请求 (function(){ const o = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(m,url){ this._url = url; this._h = {}; const s = this.setRequestHeader; this.setRequestHeader = (k,v)=>{this._h[k]=v;s.call(this,k,v);}; o.apply(this,arguments); }; const s = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function(d){ if(!captured && this._url.includes('agj_api.php?action=generate')){ captured = true; requestTemplate = {method:'POST', url:this._url, headers:this._h, body:d}; } s.call(this,d); }; })(); // 只在 agj.php 显示 if (location.pathname === '/agj.php') { window.addEventListener('DOMContentLoaded', createPanel); } })();