emoji class for DTF-markdown

emoji class

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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         emoji class for DTF-markdown
// @namespace    https://github.com/TentacleTenticals
// @version      0.0.1
// @description  emoji class
// @author       Tentacle Tenticals
// @match        https://dtf.ru/*
// @license MIT
// @require https://greasyfork.org/scripts/455674-emoji-for-dtf-markdown/code/emoji%20for%20DTF-markdown.js
// ==/UserScript==
 
(function () {
'use strict';

class Emoji {
  constructor({ path, name, url, type }) {
    // this.m=document.createElement('div');
    // this.m.className='emojiContainer';
    // path.appendChild(this.m);

    // this.name=document.createElement('p');
    // this.name.className='emojiName';
    // this.name.textContent='';
    // this.name.textContent=name;
    // this.m.appendChild(this.name);

    this.mask = document.createElement('div');
    this.mask.className = 'emojiMask';
    path.appendChild(this.mask);

    type === 'animated' ? (this.e = document.createElement('video')) : (this.e = document.createElement('img'));
    this.e.className = 'emoji';
    this.e.src = url;
    this.e.onclick = () => {
      document.querySelector(
        `div[class='writeComment']`
      ).innerHTML += `::${name}::`;
      document.querySelector(`div[class='emojiPicker']`).remove();
    };
    this.e.onmouseenter = () => {
      this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[1].textContent = `:${name}:`;
      type === 'animated' ? (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[1].src =
            url)
        : (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[0].src =
            url);
    };
    this.e.onmouseleave = () => {
      this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[1].textContent =
        '';
      type === 'animated' ? (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[1].src =
            '')
        : (this.e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[2].children[0].src =
            '');
    };
    this.mask.appendChild(this.e);
  }
}

class EmojiPicker {
  constructor(path) {
    if(document.getElementById('emojiPicker')) return;
    this.d = document.createElement('div');
    this.d.className = 'emojiPicker';
    this.d.id='emojiPicker';
    path.appendChild(this.d);

    this.title = document.createElement('div');
    this.title.className = 'title';
    this.title.textContent = 'EMOJI PICKER';
    this.title.onclick=() => {
      this.d.remove();
    }
    this.d.appendChild(this.title);

    this.field = document.createElement('div');
    this.field.className = 'emojiPicker-field';
    this.d.appendChild(this.field);

    // this.fieldPreviewName=document.createElement('div');
    // this.d.appendChild(this.fieldPreviewName);
    this.fieldPreview = document.createElement('div');
    this.fieldPreview.style = `
    display: flex;
    height: 70px;
    flex-direction: column;
    `;
    this.d.appendChild(this.fieldPreview);
    this.image = document.createElement('img');
    this.image.style = `
    position: relative;
    margin: auto;
    max-width: 70px;
    max-height: 70px;
    `;
    this.fieldPreview.appendChild(this.image);
    this.video = document.createElement('video');
    this.video.style = `
    position: relative;
    margin: auto;
    max-width: 70px;
    max-height: 70px;
    `;
    this.video.setAttribute('autoplay', '');
    this.fieldPreview.appendChild(this.video);

    this.na = document.createElement('div');
    this.d.appendChild(this.na);
    this.naLabel = document.createElement('div');
    this.naLabel.textContent = 'Not animated';
    this.naLabel.style = `
    text-align: center;
    color: white;
    margin-top: 5px;
    box-shadow: inset 0px 0px 8px 0px rgb(134 167 185);
    cursor: pointer;`;
    this.naLabel.onclick = () => {
      this.naLabel.nextElementSibling.classList.toggle('hidden');
    };
    this.na.appendChild(this.naLabel);

    this.emojiList = document.createElement('div');
    this.emojiList.className = 'groupList';
    this.na.appendChild(this.emojiList);

    this.a = document.createElement('div');
    this.d.appendChild(this.a);
    this.aLabel = document.createElement('div');
    this.aLabel.textContent = 'Animated';
    this.aLabel.style = `
    text-align: center;
    color: white;
    box-shadow: inset 0px 0px 8px 0px rgb(134 167 185);
    cursor: pointer;`;
    this.aLabel.onclick = () => {
      this.aLabel.nextElementSibling.classList.toggle('hidden');
    };
    this.a.appendChild(this.aLabel);

    this.animatedEmojiList = document.createElement('div');
    this.animatedEmojiList.className = 'groupList';
    this.a.appendChild(this.animatedEmojiList);

    // for(let group in emoji){
    //   for(let emj in emoji[group]){
    //     new Emoji({
    //       url: emoji[group][emj],
    //       name: emj,
    //       path : this.emojiList
    //     })
    //   }
    // }
    new EmojiGroup({
      path: this.emojiList,
      type: 'not animated',
    });
    new EmojiGroup({
      path: this.animatedEmojiList,
      type: 'animated',
    });
  }
}

class EmojiGroup {
  constructor({ path, type }) {
    // this.eg=document.createElement('div');
    // type === 'animated' ? this.eg.textContent='Animated' : this.eg.textContent='Not animated';
    // this.eg.style=`
    // text-align: center;
    // color: white;`;
    // path.appendChild(this.eg);

    for (let group in emoji[type]) {
      this.main = document.createElement('div');
      this.main.className = 'emojiGroup';
      path.appendChild(this.main);

      this.name = document.createElement('div');
      this.name.className = 'groupName';
      this.name.textContent = group;
      this.main.appendChild(this.name);

      this.g = document.createElement('div');
      this.g.className = 'emojiList';
      this.main.appendChild(this.g);

      for (let emj in emoji[type][group]) {
        new Emoji({
          url: emoji[type][group][emj],
          name: emj,
          path: this.g,
          type: type,
        });
      }
    }
  }
}

 
})();