Files
personal82555 10c7dc0559 init: WechatSync 扩展 v2.1.3(公众号多账号保活 + 常开桥接)
- ✨ 公众号多账号保持在线:DNR 注入 Cookie 定时保活,多号互不干扰
- ✨ 公众号在线管理页(添加/检测/间隔/同步目标账号)
- ✨ 同步桥接始终连接、默认开启且锁定不可关闭
- ✨ 内置默认桥接地址 ws://192.168.68.19:9600 与服务端 Token(开箱即连)
- ✨ 独立窗口打开扩展(常驻保持,不随点击关闭)
- 🐛 桥接服务端区分扩展/观察者,修复 Hermes MCP 抢占扩展槽位
- 🐛 MCP 适配器按请求 id 分发响应,修复响应被读循环吞掉
2026-10-23 18:38:40 +08:00

106 lines
2.1 KiB
JavaScript

(function() {
console.log('api ready');
var poster = {
versionNumber: 1001,
dev: location.hostname === 'localhost' || location.hostname === '127.0.0.1',
};
var eventCb = {};
var _statueandler = null;
var _consolehandler = null;
function callFunc(msg, cb) {
msg.eventID = Math.floor(Date.now() + Math.random() * 100);
eventCb[msg.eventID] = function(err, res) {
cb(err, res);
};
window.postMessage(JSON.stringify(msg), '*');
}
poster.getAccounts = function(cb) {
callFunc(
{
method: 'getAccounts',
},
cb
);
};
poster.addTask = function(task, statueandler, cb) {
_statueandler = statueandler;
callFunc(
{
method: 'addTask',
task: task,
},
cb
);
};
poster.magicCall = function(data, cb) {
callFunc(
{
method: 'magicCall',
methodName: data.methodName,
data: data,
},
cb
);
};
poster.updateDriver = function(data, cb) {
callFunc(
{
method: 'updateDriver',
data: data,
},
cb
);
};
poster.startInspect = function(handler, cb) {
_consolehandler = handler;
callFunc(
{
method: 'startInspect',
},
cb
);
};
poster.uploadImage = function(data, cb) {
callFunc(
{
method: 'magicCall',
methodName: 'uploadImage',
data: data,
},
cb
);
};
window.addEventListener('message', function(evt) {
try {
var action = JSON.parse(evt.data);
if (action.method && action.method === 'taskUpdate') {
if (_statueandler != null) _statueandler(action.task);
return;
}
if (action.method && action.method === 'consoleLog') {
if (_consolehandler != null) _consolehandler(action.args);
return;
}
if (!action.callReturn) return;
if (action.eventID && eventCb[action.eventID]) {
eventCb[action.eventID](action.result);
delete eventCb[action.eventID];
}
} catch (e) {}
});
window.$poster = poster;
window.$syncer = poster;
})();