NodeSeek 表情包增强

为 NodeSeek 添加更多表情包

目前为 2024-02-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name NodeSeek 表情包增强
  3. // @namespace https://www.nodeseek.com/
  4. // @version 0.0.5
  5. // @description 为 NodeSeek 添加更多表情包
  6. // @author TomyJan
  7. // @match *://www.nodeseek.com/*
  8. // @icon https://www.nodeseek.com/static/image/favicon/android-chrome-192x192.png
  9. // @grant none
  10. // @license MPL-2.0 License
  11. // @supportURL https://www.nodeseek.com/post-68803-1
  12. // @homepageURL https://www.nodeseek.com/post-68803-1
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. // 自定义表情包数据
  19. // 添加其它自定义表情包请参照以下格式
  20. const customEmotionList = {
  21. // bili 表情包来自 https://github.com/lrhtony/BiliEmoji
  22. "2233娘": { "name": "2233娘", "type": "png", "icon": "icon", "items": ["2233娘-大笑", "2233娘-吃惊", "2233娘-大哭", "2233娘-耶", "2233娘-卖萌", "2233娘-疑问", "2233娘-汗", "2233娘-困惑", "2233娘-怒", "2233娘-委屈", "2233娘-郁闷", "2233娘-第一", "2233娘-喝水", "2233娘-吐魂", "2233娘-无言"], "baseUrl": "https://emoji.shojo.cn/bili/src/2233娘/" },
  23. "小电视": {"name": "小电视", "type": "gif", "icon": "icon", "items": ["tvgif-白眼", "tvgif-doge", "tvgif-坏笑", "tvgif-难过", "tvgif-生气", "tvgif-委屈", "tvgif-斜眼笑", "tvgif-呆", "tvgif-发怒", "tvgif-惊吓", "tvgif-呕吐", "tvgif-思考", "tvgif-微笑", "tvgif-疑问", "tvgif-大哭", "tvgif-鼓掌", "tvgif-抠鼻", "tvgif-亲亲", "tvgif-调皮", "tvgif-笑哭", "tvgif-晕", "tvgif-点赞", "tvgif-害羞", "tvgif-睡着", "tvgif-色", "tvgif-吐血", "tvgif-无奈", "tvgif-再见", "tvgif-流汗", "tvgif-偷笑", "tvgif-抓狂", "tvgif-黑人问号", "tvgif-困", "tvgif-打脸", "tvgif-闭嘴", "tvgif-鄙视", "tvgif-腼腆", "tvgif-馋", "tvgif-可爱", "tvgif-发财", "tvgif-生病", "tvgif-流鼻血", "tvgif-尴尬", "tvgif-大佬"], "baseUrl": "https://emoji.shojo.cn/bili/src/tv_小电视_动图/" },
  24. // 贴吧表情包来自 https://github.com/microlong666/Tieba_mobile_emotions
  25. "贴吧": {"name": "贴吧", "type": "png", "items": ["image_emoticon", "image_emoticon2", "image_emoticon3", "image_emoticon4", "image_emoticon5", "image_emoticon6", "image_emoticon7", "image_emoticon8", "image_emoticon9", "image_emoticon10", "image_emoticon11", "image_emoticon12", "image_emoticon13", "image_emoticon14", "image_emoticon15", "image_emoticon16", "image_emoticon17", "image_emoticon18", "image_emoticon19", "image_emoticon20", "image_emoticon21", "image_emoticon22", "image_emoticon23", "image_emoticon24", "image_emoticon25", "image_emoticon26", "image_emoticon27", "image_emoticon28", "image_emoticon29", "image_emoticon30", "image_emoticon31", "image_emoticon32", "image_emoticon33", "image_emoticon34", "image_emoticon35", "image_emoticon36", "image_emoticon37", "image_emoticon38", "image_emoticon39", "image_emoticon40", "image_emoticon41", "image_emoticon42", "image_emoticon43", "image_emoticon44", "image_emoticon45", "image_emoticon46", "image_emoticon47", "image_emoticon48", "image_emoticon49", "image_emoticon50", "image_emoticon62", "image_emoticon63", "image_emoticon64", "image_emoticon65", "image_emoticon66", "image_emoticon67", "image_emoticon68", "image_emoticon69", "image_emoticon70", "image_emoticon71", "image_emoticon72", "image_emoticon73", "image_emoticon74", "image_emoticon75", "image_emoticon76", "image_emoticon77", "image_emoticon78", "image_emoticon79", "image_emoticon80", "image_emoticon81", "image_emoticon82", "image_emoticon83", "image_emoticon84", "image_emoticon85", "image_emoticon86", "image_emoticon87", "image_emoticon88", "image_emoticon89", "image_emoticon90", "image_emoticon91", "image_emoticon92", "image_emoticon93", "image_emoticon94", "image_emoticon95", "image_emoticon96", "image_emoticon97", "image_emoticon98", "image_emoticon99", "image_emoticon100", "image_emoticon101", "image_emoticon102", "image_emoticon103", "image_emoticon104", "image_emoticon105", "image_emoticon106", "image_emoticon107", "image_emoticon108", "image_emoticon109", "image_emoticon110", "image_emoticon111", "image_emoticon112", "image_emoticon113", "image_emoticon114", "image_emoticon115", "image_emoticon116", "image_emoticon117", "image_emoticon118", "image_emoticon119", "image_emoticon120", "image_emoticon121", "image_emoticon122", "image_emoticon123", "image_emoticon124"], "baseUrl": "https://cdn.jsdelivr.net/gh/microlong666/tieba_mobile_emotions/" },
  26. // 小恐龙和花表情包来自 https://github.com/solstice23/argon-theme
  27. "小恐龙": {"name": "小恐龙", "type": "jpg", "items": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"], "baseUrl": "https://cdn.jsdelivr.net/gh/solstice23/argon-theme/stickers/dinosaur/"},
  28. "花!": {"name": "花!", "type": "PNG", "items": ["花", "草", "叶", "星", "日", "月", "水", "嘿嘿", "酸", "生日快乐", "海", "菜", "瓦", "�"], "baseUrl": "https://cdn.jsdelivr.net/gh/k4yt3x/flowerhd/PNG/"}
  29. };
  30.  
  31. // 页面加载完毕后初始化自定义表情包
  32. window.addEventListener('load', initCustomEmotions, false);
  33.  
  34. function initCustomEmotions() {
  35. setupEmotionTitles();
  36. setupEmotionTitlesClickHandler();
  37. monitorExpContainerChanges();
  38. }
  39.  
  40. // 设置自定义表情包标题
  41. function setupEmotionTitles() {
  42. const emotionTitleDiv = document.querySelector('.expression');
  43. Object.keys(customEmotionList).forEach(key => {
  44. const newDiv = createEmotionTitle(key);
  45. emotionTitleDiv.appendChild(newDiv);
  46. });
  47. }
  48.  
  49. // 创建表情包标题元素
  50. function createEmotionTitle(key) {
  51. const newDiv = document.createElement('div');
  52. newDiv.id = `custom-emotion-${key}`;
  53. newDiv.classList.add('custom-emotion');
  54. newDiv.innerHTML = ` ${customEmotionList[key].name} `;
  55. newDiv.style.cursor = 'pointer';
  56. addHoverEffect(newDiv);
  57. return newDiv;
  58. }
  59.  
  60. // 添加标题鼠标悬浮效果
  61. function addHoverEffect(element) {
  62. element.addEventListener('mouseenter', () => {
  63. element.style.transform = 'scale(1.1)';
  64. element.style.transition = 'transform 0.3s ease';
  65. });
  66.  
  67. element.addEventListener('mouseleave', () => {
  68. element.style.transform = 'scale(1)';
  69. });
  70. }
  71.  
  72. // 设置自定义表情包标题的点击事件处理
  73. function setupEmotionTitlesClickHandler() {
  74. document.querySelectorAll('.expression .custom-emotion').forEach(item => {
  75. item.addEventListener('click', () => {
  76. handleCustomEmotionClick(item);
  77. });
  78. });
  79. }
  80.  
  81. // 处理点击自定义表情包标题事件
  82. function handleCustomEmotionClick(clickedItem) {
  83. const containerDiv = document.querySelector('.exp-container');
  84.  
  85. // // 判断 containerDiv 的内容里面是不是包含 <!----> , 如果不包含就说明官方表情包打开了
  86. const isOfficial = containerDiv.innerHTML.indexOf('<!---->') === -1;
  87.  
  88.  
  89. const isCurrent = clickedItem.classList.contains('current-group');
  90. const isOpen = containerDiv.classList.contains('open');
  91.  
  92.  
  93.  
  94.  
  95. // 如果容器未打开或当前选中的不是点击的标题或者打开了官方表情包,则更新显示
  96. if (!isOpen || !isCurrent || isOfficial) {
  97. if (isOfficial) { // 打开了官方表情包
  98. document.querySelector('.exp-item.current-group').click();
  99. setTimeout(() => {
  100. if (containerDiv.classList.contains('open')) { // 判断官方表情包是否已经关闭
  101. return; // 关不掉就别干了吧
  102. // TODO: 一个更好的方法避免这俩共存
  103. }
  104. updateEmotionDisplay(clickedItem, containerDiv);
  105. }, 500);
  106. } else
  107. updateEmotionDisplay(clickedItem, containerDiv);
  108. } else { // 否则,清除并关闭
  109. // console.log('clear and close');
  110. containerDiv.classList.remove('open');
  111. clearEmotions();
  112. }
  113. }
  114.  
  115. // 更新表情包显示
  116. function updateEmotionDisplay(clickedItem, containerDiv) {
  117. clearEmotions(); // 清除当前显示的表情包
  118. document.querySelectorAll('.expression .custom-emotion').forEach(item => {
  119. item.classList.remove('current-group');
  120. });
  121.  
  122. clickedItem.classList.add('current-group');
  123. addEmotionsToContainer(clickedItem.id.replace('custom-emotion-', ''), containerDiv);
  124. containerDiv.classList.add('open');
  125. }
  126.  
  127. // 清除表情包显示容器中的内容
  128. function clearEmotions() {
  129. const tempContainer = document.getElementById('temporary-container');
  130. tempContainer?.remove(); // 如果临时容器存在,则移除
  131. }
  132.  
  133. // 向显示容器中添加表情包
  134. function addEmotionsToContainer(packKey, containerDiv) {
  135. const pack = customEmotionList[packKey];
  136. const container = document.createElement('div');
  137. container.id = 'temporary-container';
  138.  
  139. pack.items.forEach(item => {
  140. const img = document.createElement('img');
  141. img.src = `${pack.baseUrl}/${item}.${pack.type}`;
  142. img.alt = item;
  143. img.className = "sticker";
  144. img.style.maxWidth = "90px";
  145. container.appendChild(img);
  146. });
  147.  
  148. // 给表情包图片添加点击事件
  149. container.addEventListener('click', (e) => {
  150. insertToEditor(e.target.alt, e.target.src);
  151. });
  152.  
  153. containerDiv.appendChild(container);
  154. }
  155.  
  156. // 向编辑器中插入图片链接
  157. function insertToEditor(imgName, imgLink) {
  158. const codeMirrorElement = document.querySelector('.CodeMirror');
  159. if (codeMirrorElement) {
  160. const codeMirrorInstance = codeMirrorElement.CodeMirror;
  161. if (codeMirrorInstance) {
  162. const cursor = codeMirrorInstance.getCursor();
  163. codeMirrorInstance.replaceRange(` ![表情包-${imgName}](${imgLink}) `, cursor);
  164. }
  165. }
  166. }
  167.  
  168. // 监视表情包显示容器的变化, 防止同时打开官方和自定义
  169. function monitorExpContainerChanges() {
  170. // 选择要观察变动的节点
  171. const targetNode = document.querySelector('.exp-container');
  172.  
  173. // 创建一个回调函数来接收变动通知
  174. const callback = function (mutationsList, observer) {
  175. // 检查.exp-container的innerHTML是否不包含'<!---->'即打开了官方表情包
  176. if (!targetNode.innerHTML.includes('<!---->')) {
  177. clearEmotions(); // 防止官方和自定义同时存在
  178. // 遍历所有.expression .custom-emotion类的元素并禁用
  179. // const customEmotions = document.querySelectorAll('.expression .custom-emotion');
  180. // customEmotions.forEach(element => {
  181. // element.disabled = true; // 这里假设这些元素是可以被禁用的,比如按钮
  182. // // 如果元素不能直接被禁用,可能需要添加逻辑来处理(比如添加一个类或属性来表示禁用状态)
  183. // });
  184. }
  185. };
  186.  
  187. // 创建MutationObserver实例并传入回调函数
  188. const observer = new MutationObserver(callback);
  189.  
  190. // 使用配置对象指定要观察的变动类型
  191. const config = { childList: true, subtree: true, characterData: true };
  192.  
  193. // 开始观察目标节点
  194. observer.observe(targetNode, config);
  195.  
  196. // 注意:在某个时刻,你可能需要停止观察
  197. // observer.disconnect();
  198. }
  199.  
  200. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址