emoji class for DTF-markdown

emoji class

当前为 2022-11-30 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/455678/1123008/emoji%20class%20for%20DTF-markdown.js

  1. // ==UserScript==
  2. // @name emoji class for DTF-markdown
  3. // @namespace https://github.com/TentacleTenticals
  4. // @version 0.0.1
  5. // @description emoji class
  6. // @author Tentacle Tenticals
  7. // @license MIT
  8. // @require https://greasyfork.org/scripts/455674-emoji-for-dtf-markdown/code/emoji%20for%20DTF-markdown.js
  9. // ==/UserScript==
  10. (function () {
  11. 'use strict';
  12.  
  13. window.Emoji = class Emoji {
  14. constructor({ path, name, url, type }) {
  15. // this.m=document.createElement('div');
  16. // this.m.className='emojiContainer';
  17. // path.appendChild(this.m);
  18.  
  19. // this.name=document.createElement('p');
  20. // this.name.className='emojiName';
  21. // this.name.textContent='';
  22. // this.name.textContent=name;
  23. // this.m.appendChild(this.name);
  24.  
  25. this.mask = document.createElement('div');
  26. this.mask.className = 'emojiMask';
  27. path.appendChild(this.mask);
  28.  
  29. type === 'animated' ? (this.e = document.createElement('video')) : (this.e = document.createElement('img'));
  30. this.e.className = 'emoji';
  31. this.e.src = url;
  32. this.e.onclick = () => {
  33. document.querySelector(
  34. `div[class='writeComment']`
  35. ).innerHTML += `::${name}::`;
  36. document.querySelector(`div[class='emojiPicker']`).remove();
  37. };
  38. this.e.onmouseenter = () => {
  39. this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[1].textContent = `:${name}:`;
  40. type === 'animated' ? (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[1].src =
  41. url)
  42. : (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[0].src =
  43. url);
  44. };
  45. this.e.onmouseleave = () => {
  46. this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[1].textContent =
  47. '';
  48. type === 'animated' ? (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[1].src =
  49. '')
  50. : (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[0].src =
  51. '');
  52. };
  53. this.mask.appendChild(this.e);
  54. }
  55. }
  56.  
  57. class EmojiPicker {
  58. constructor(path) {
  59. if(document.getElementById('emojiPicker')) return;
  60. this.d = document.createElement('div');
  61. this.d.className = 'emojiPicker';
  62. this.d.id='emojiPicker';
  63. path.appendChild(this.d);
  64.  
  65. this.title = document.createElement('div');
  66. this.title.className = 'title';
  67. this.title.textContent = 'EMOJI PICKER';
  68. this.title.onclick=() => {
  69. this.d.remove();
  70. }
  71. this.d.appendChild(this.title);
  72.  
  73. this.field = document.createElement('div');
  74. this.field.className = 'emojiPicker-field';
  75. this.d.appendChild(this.field);
  76.  
  77. // this.fieldPreviewName=document.createElement('div');
  78. // this.d.appendChild(this.fieldPreviewName);
  79. this.fieldPreview = document.createElement('div');
  80. this.fieldPreview.style = `
  81. display: flex;
  82. height: 70px;
  83. flex-direction: column;
  84. `;
  85. this.d.appendChild(this.fieldPreview);
  86. this.image = document.createElement('img');
  87. this.image.style = `
  88. position: relative;
  89. margin: auto;
  90. max-width: 70px;
  91. max-height: 70px;
  92. `;
  93. this.fieldPreview.appendChild(this.image);
  94. this.video = document.createElement('video');
  95. this.video.style = `
  96. position: relative;
  97. margin: auto;
  98. max-width: 70px;
  99. max-height: 70px;
  100. `;
  101. this.video.setAttribute('autoplay', '');
  102. this.fieldPreview.appendChild(this.video);
  103.  
  104. this.na = document.createElement('div');
  105. this.d.appendChild(this.na);
  106. this.naLabel = document.createElement('div');
  107. this.naLabel.textContent = 'Not animated';
  108. this.naLabel.style = `
  109. text-align: center;
  110. color: white;
  111. margin-top: 5px;
  112. box-shadow: inset 0px 0px 8px 0px rgb(134 167 185);
  113. cursor: pointer;`;
  114. this.naLabel.onclick = () => {
  115. this.naLabel.nextElementSibling.classList.toggle('hidden');
  116. };
  117. this.na.appendChild(this.naLabel);
  118.  
  119. this.emojiList = document.createElement('div');
  120. this.emojiList.className = 'groupList';
  121. this.na.appendChild(this.emojiList);
  122.  
  123. this.a = document.createElement('div');
  124. this.d.appendChild(this.a);
  125. this.aLabel = document.createElement('div');
  126. this.aLabel.textContent = 'Animated';
  127. this.aLabel.style = `
  128. text-align: center;
  129. color: white;
  130. box-shadow: inset 0px 0px 8px 0px rgb(134 167 185);
  131. cursor: pointer;`;
  132. this.aLabel.onclick = () => {
  133. this.aLabel.nextElementSibling.classList.toggle('hidden');
  134. };
  135. this.a.appendChild(this.aLabel);
  136.  
  137. this.animatedEmojiList = document.createElement('div');
  138. this.animatedEmojiList.className = 'groupList';
  139. this.a.appendChild(this.animatedEmojiList);
  140.  
  141. // for(let group in emoji){
  142. // for(let emj in emoji[group]){
  143. // new Emoji({
  144. // url: emoji[group][emj],
  145. // name: emj,
  146. // path : this.emojiList
  147. // })
  148. // }
  149. // }
  150. new EmojiGroup({
  151. path: this.emojiList,
  152. type: 'not animated',
  153. });
  154. new EmojiGroup({
  155. path: this.animatedEmojiList,
  156. type: 'animated',
  157. });
  158. }
  159. }
  160.  
  161. class EmojiGroup {
  162. constructor({ path, type }) {
  163. // this.eg=document.createElement('div');
  164. // type === 'animated' ? this.eg.textContent='Animated' : this.eg.textContent='Not animated';
  165. // this.eg.style=`
  166. // text-align: center;
  167. // color: white;`;
  168. // path.appendChild(this.eg);
  169.  
  170. for (let group in emoji[type]) {
  171. this.main = document.createElement('div');
  172. this.main.className = 'emojiGroup';
  173. path.appendChild(this.main);
  174.  
  175. this.name = document.createElement('div');
  176. this.name.className = 'groupName';
  177. this.name.textContent = group;
  178. this.main.appendChild(this.name);
  179.  
  180. this.g = document.createElement('div');
  181. this.g.className = 'emojiList';
  182. this.main.appendChild(this.g);
  183.  
  184. for (let emj in emoji[type][group]) {
  185. new Emoji({
  186. url: emoji[type][group][emj],
  187. name: emj,
  188. path: this.g,
  189. type: type,
  190. });
  191. }
  192. }
  193. }
  194. }
  195.  
  196. })();