mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: send poke by context menu, only support group chat
This commit is contained in:
parent
99693abd06
commit
5d73250fc5
@ -1,7 +1,7 @@
|
||||
//LiteLoader需要提供部分IPC接口,以便于其他插件调用
|
||||
const { ipcMain } = require('electron');
|
||||
const napcat = require('./napcat.cjs');
|
||||
require('./poke/main.js');
|
||||
require('./poke/main.cjs');
|
||||
|
||||
ipcMain.handle('napcat_get_webtoken', async (event, arg) => {
|
||||
return napcat.NCgetWebUiUrl();
|
||||
|
@ -52,6 +52,7 @@ export async function NCoreInitFramework(
|
||||
InitWebUi(logger, pathWrapper).then().catch(logger.logError.bind(logger));
|
||||
//初始化LLNC的Onebot实现
|
||||
new NapCatOneBot11Adapter(loaderObject.core, loaderObject.context, pathWrapper);
|
||||
return loaderObject;
|
||||
}
|
||||
|
||||
export class NapCatFramework {
|
||||
|
20
src/framework/poke/main.cjs
Normal file
20
src/framework/poke/main.cjs
Normal file
@ -0,0 +1,20 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const napcat = require('../napcat.cjs');
|
||||
|
||||
|
||||
ipcMain.handle('napcat_group_poke', async (event, { messageId, groupName }) => {
|
||||
const framework = await napcat.napcatFramework;
|
||||
const groups = await framework.core.apis.GroupApi.groupCache;
|
||||
const matchingGroups = Array.from(groups.values()).filter(group => group.groupName === groupName);
|
||||
|
||||
for (const group of matchingGroups) {
|
||||
const { msgList } = await framework.core.apis.MsgApi.getMsgsByMsgId({
|
||||
peerUid: group.groupCode,
|
||||
chatType: 2
|
||||
}, [messageId]);
|
||||
if (msgList) {
|
||||
await framework.core.apis.PacketApi.sendPokePacket(+(msgList[0].senderUin), +group.groupCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
@ -1,20 +0,0 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const napcat = require('../napcat.cjs');
|
||||
|
||||
|
||||
ipcMain.handle('napcat_group_poke', async (event, { messageId, groupName }) => {
|
||||
const framework = await napcat.napcatFramework;
|
||||
const groups = await framework.core.apis.getGroups();
|
||||
for (const group of groups) {
|
||||
if (groupName === group.groupName) {
|
||||
const { msgList } = await framework.core.apis.getMsgsByMsgId({
|
||||
peerUid: group.groupCode,
|
||||
chatType: 2
|
||||
}, [messageId]);
|
||||
if (msgList) {
|
||||
framework.core.apis.PacketApi.sendPokePacket(msgList[0].senderUin, +group.groupCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
@ -1,11 +1,48 @@
|
||||
function onLoad() {
|
||||
document.getElementsByClassName("avatar").forEach(e => e.addEventListener("contextmenu", (ee) => {
|
||||
let messageEle = ee.target.parentElement.parentElement.parentElement.parentElement;
|
||||
let messageId = messageEle.getAttribute("id");
|
||||
let groupName = document.getElementsByClassName("chat-header__contact-name")[0].firstElementChild.textContent.trim();
|
||||
// todo: 右键菜单添加戳一戳
|
||||
window.napcat.groupPoke(groupName, messageId);
|
||||
}));
|
||||
export function injectPokeMenu() {
|
||||
|
||||
console.log('Inject poke menu...');
|
||||
|
||||
// 选择目标节点
|
||||
const targetNode = document.body;
|
||||
console.log(targetNode);
|
||||
// 配置需要观察的变动类型
|
||||
const config = {
|
||||
childList: true, // 观察子节点的变动
|
||||
subtree: true // 观察后代节点
|
||||
};
|
||||
|
||||
// 创建一个回调函数,当变动发生时执行
|
||||
const callback = function(mutationsList, observer) {
|
||||
// console.log(mutationsList);
|
||||
for (const mutation of mutationsList) {
|
||||
// console.log(mutation.addedNodes);
|
||||
if (mutation.type === 'childList') {
|
||||
mutation.addedNodes.forEach(node => {
|
||||
if (node?.previousSibling?.classList?.contains('q-context-menu')){
|
||||
const r = node.previousSibling.getBoundingClientRect();
|
||||
const rightClickEle = document.elementFromPoint(r.x, r.y);
|
||||
console.log("右击的元素", rightClickEle);
|
||||
if (rightClickEle.classList?.contains('avatar')){
|
||||
node.previousSibling.insertAdjacentHTML('beforeend', '<a class="q-context-menu-item q-context-menu-item-normal poke-menu"><span class="q-context-menu-item__text">戳一戳</span></a>');
|
||||
node.previousSibling.querySelector('.poke-menu').addEventListener('click', e=>{
|
||||
let messageEle = rightClickEle.parentElement.parentElement.parentElement.parentElement;
|
||||
let messageId = messageEle.id;
|
||||
const groupName = document.getElementsByClassName("chat-header__contact-name")[0].firstElementChild.textContent.trim();
|
||||
window.napcat.groupPoke(groupName, messageId);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 创建一个新的观察者实例并传入回调函数
|
||||
const observer = new MutationObserver(callback);
|
||||
|
||||
// 开始观察目标节点并传入配置
|
||||
observer.observe(targetNode, config);
|
||||
}
|
||||
|
||||
onLoad();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
require('./poke/renderer.js');
|
||||
import { injectPokeMenu } from './poke/renderer.js';
|
||||
export const onSettingWindowCreated = async (view) => {
|
||||
|
||||
|
||||
// view.style.width = "100%";
|
||||
// view.style.height = "100%";
|
||||
// //添加iframe
|
||||
@ -35,3 +35,27 @@ export const onSettingWindowCreated = async (view) => {
|
||||
});
|
||||
view.querySelector('.nc_webui').innerText = webui;
|
||||
};
|
||||
|
||||
function onLoad() {
|
||||
if (location.hash === "#/blank") {
|
||||
navigation.addEventListener("navigatesuccess", updateHash, { once: true });
|
||||
} else {
|
||||
updateHash();
|
||||
}
|
||||
|
||||
function updateHash() {
|
||||
let hash = location.hash;
|
||||
if (hash === "#/blank") {
|
||||
return;
|
||||
}
|
||||
if (hash.includes("#/main/message")) {
|
||||
console.log(location);
|
||||
injectPokeMenu();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
onLoad();
|
||||
|
Loading…
x
Reference in New Issue
Block a user