// ==UserScript== // @name 本地页面 GM 接口桥接 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 将 ScriptCat 的 GM 接口暴露给本地 file:// 页面环境 // @author You // @match file:///* // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_notification // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 确保能够获取到页面的 window 对象 if (typeof unsafeWindow !== 'undefined') { // 1. 暴露 GM_xmlhttpRequest (跨域请求) if (typeof GM_xmlhttpRequest !== 'undefined') { unsafeWindow.GM_xmlhttpRequest = GM_xmlhttpRequest; } // 2. 暴露数据存储接口 if (typeof GM_setValue !== 'undefined') unsafeWindow.GM_setValue = GM_setValue; if (typeof GM_getValue !== 'undefined') unsafeWindow.GM_getValue = GM_getValue; if (typeof GM_deleteValue !== 'undefined') unsafeWindow.GM_deleteValue = GM_deleteValue; // 3. 暴露系统通知接口 if (typeof GM_notification !== 'undefined') unsafeWindow.GM_notification = GM_notification; console.log('[ScriptCat Bridge] GM 接口已成功暴露至 window 对象'); } })();