代码拉取完成,页面将自动刷新
/**
* Add the send as button to the group chat member icons.
* @returns {void}
*/
function addSendAsButton() {
const button = document.createElement('div');
button.title = 'Send as a character';
button.classList.add('send_as', 'right_menu_button', 'fa-solid', 'fa-quote-right');
button.setAttribute('data-i18n', '[title]Send as a character');
const template = document.querySelector('#group_member_template .group_member_icon');
if (!template) return;
template.prepend(button);
}
/**
* Add event listener to the document.
* @returns {void}
*/
function addEventListener() {
document.addEventListener('click', function (event) {
if (event.target instanceof HTMLElement && event.target.matches('.send_as')) {
onSendAsButtonClick(event);
}
});
}
/**
* Handle the click event on the send as button.
* @param {Event} event Click event
* @returns {void}
*/
function onSendAsButtonClick(event) {
const textArea = document.getElementById('send_textarea');
if (!textArea || !(textArea instanceof HTMLTextAreaElement)) return;
const characterName = getCharacterName(event.target);
textArea.value = `/sendas name="${characterName}" ${textArea.value}`;
textArea.focus();
}
/**
* Get the character name of the clicked group member.
* @param {EventTarget | null} target Click event target
* @returns {string} Character name
*/
function getCharacterName(target) {
if (!(target instanceof HTMLElement)) return '';
const member = target.closest('.group_member');
if (!member) return '';
const nameElement = member.querySelector('.group_member_name .ch_name');
return nameElement?.textContent || '';
}
/**
* Main function to run the extension.
*/
(function () {
addSendAsButton();
addEventListener();
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。