custom emoji picker
merges fbb7ed3c9c (diff-beb98739004ececc621a1ab4a177e04f96d8d358c215716df0dcf1e1cb0f453c)
and makes it fully functional along with CSS fixes
This commit is contained in:
parent
96faadddd0
commit
ece9ebceb5
8 changed files with 174 additions and 60 deletions
|
@ -100,13 +100,66 @@ class Emoji {
|
||||||
Emoji.decodeEmojiList(e);
|
Emoji.decodeEmojiList(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static async emojiPicker(x, y) {
|
static async emojiPicker(x, y, localuser) {
|
||||||
let res;
|
let res;
|
||||||
const promise = new Promise((r) => { res = r; });
|
const promise = new Promise((r) => { res = r; });
|
||||||
const menu = document.createElement("div");
|
const menu = document.createElement("div");
|
||||||
menu.classList.add("flextttb", "emojiPicker");
|
menu.classList.add("flextttb", "emojiPicker");
|
||||||
menu.style.top = y + "px";
|
menu.style.top = y + "px";
|
||||||
menu.style.left = x + "px";
|
menu.style.left = x + "px";
|
||||||
|
const title = document.createElement("h2");
|
||||||
|
title.textContent = Emoji.emojis[0].name;
|
||||||
|
title.classList.add("emojiTitle");
|
||||||
|
menu.append(title);
|
||||||
|
console.log("menu :3");
|
||||||
|
const selection = document.createElement("div");
|
||||||
|
selection.classList.add("flexltr", "dontshrink", "emojirow");
|
||||||
|
console.log("menu :3");
|
||||||
|
const body = document.createElement("div");
|
||||||
|
body.classList.add("emojiBody");
|
||||||
|
let isFirst = true;
|
||||||
|
localuser.guilds.filter(guild => guild.id != "@me" && guild.emojis.length > 0).forEach(guild => {
|
||||||
|
const select = document.createElement("div");
|
||||||
|
select.classList.add("emojiSelect");
|
||||||
|
if (guild.properties.icon) {
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.classList.add("pfp", "servericon", "emoji-server");
|
||||||
|
img.crossOrigin = "anonymous";
|
||||||
|
img.src = localuser.info.cdn + "/icons/" + guild.properties.id + "/" + guild.properties.icon + ".png?size=48";
|
||||||
|
img.alt = "Server: " + guild.properties.name;
|
||||||
|
select.appendChild(img);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const div = document.createElement("span");
|
||||||
|
div.textContent = guild.properties.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "");
|
||||||
|
select.append(div);
|
||||||
|
}
|
||||||
|
selection.append(select);
|
||||||
|
const clickEvent = () => {
|
||||||
|
title.textContent = guild.properties.name;
|
||||||
|
body.innerHTML = "";
|
||||||
|
for (const emojit of guild.emojis) {
|
||||||
|
const emojiElem = document.createElement("div");
|
||||||
|
emojiElem.classList.add("emojiSelect");
|
||||||
|
const emojiClass = new Emoji({
|
||||||
|
id: emojit.id,
|
||||||
|
name: emojit.name,
|
||||||
|
animated: emojit.animated
|
||||||
|
}, localuser);
|
||||||
|
emojiElem.append(emojiClass.getHTML());
|
||||||
|
body.append(emojiElem);
|
||||||
|
emojiElem.addEventListener("click", () => {
|
||||||
|
res(emojiClass);
|
||||||
|
Contextmenu.currentmenu.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
select.addEventListener("click", clickEvent);
|
||||||
|
if (isFirst) {
|
||||||
|
clickEvent();
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (Contextmenu.currentmenu != "") {
|
if (Contextmenu.currentmenu != "") {
|
||||||
Contextmenu.currentmenu.remove();
|
Contextmenu.currentmenu.remove();
|
||||||
|
@ -115,16 +168,6 @@ class Emoji {
|
||||||
Contextmenu.currentmenu = menu;
|
Contextmenu.currentmenu = menu;
|
||||||
Contextmenu.keepOnScreen(menu);
|
Contextmenu.keepOnScreen(menu);
|
||||||
}, 10);
|
}, 10);
|
||||||
const title = document.createElement("h2");
|
|
||||||
title.textContent = Emoji.emojis[0].name;
|
|
||||||
title.classList.add("emojiTitle");
|
|
||||||
menu.append(title);
|
|
||||||
console.log("menu :3");
|
|
||||||
const selection = document.createElement("div");
|
|
||||||
selection.classList.add("flexltr", "dontshrink");
|
|
||||||
console.log("menu :3");
|
|
||||||
const body = document.createElement("div");
|
|
||||||
body.classList.add("emojiBody");
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const thing of Emoji.emojis) {
|
for (const thing of Emoji.emojis) {
|
||||||
const select = document.createElement("div");
|
const select = document.createElement("div");
|
||||||
|
|
|
@ -21,6 +21,7 @@ class Guild {
|
||||||
parent_id;
|
parent_id;
|
||||||
member;
|
member;
|
||||||
html;
|
html;
|
||||||
|
emojis;
|
||||||
get id() {
|
get id() {
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +76,7 @@ class Guild {
|
||||||
if (json === -1) {
|
if (json === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.emojis = json.emojis;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Message {
|
||||||
navigator.clipboard.writeText(this.id);
|
navigator.clipboard.writeText(this.id);
|
||||||
});
|
});
|
||||||
Message.contextmenu.addsubmenu("Add reaction", function (e) {
|
Message.contextmenu.addsubmenu("Add reaction", function (e) {
|
||||||
Emoji.emojiPicker(e.x, e.y).then(_ => {
|
Emoji.emojiPicker(e.x, e.y, this.localuser).then(_ => {
|
||||||
console.log(_, ":3");
|
console.log(_, ":3");
|
||||||
this.reactionToggle(_);
|
this.reactionToggle(_);
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,6 @@ class Message {
|
||||||
this.giveData(messagejson);
|
this.giveData(messagejson);
|
||||||
}
|
}
|
||||||
reactionToggle(emoji) {
|
reactionToggle(emoji) {
|
||||||
if (typeof emoji === "string") {
|
|
||||||
let remove = false;
|
let remove = false;
|
||||||
for (const thing of this.reactions) {
|
for (const thing of this.reactions) {
|
||||||
if (thing.emoji.name === emoji) {
|
if (thing.emoji.name === emoji) {
|
||||||
|
@ -78,14 +77,17 @@ class Message {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetch(this.info.api + "/channels/" + this.channel.id + "/messages/" + this.id + "/reactions/" + encodeURIComponent(emoji) + "/@me", {
|
let reactiontxt;
|
||||||
method: remove ? "DELETE" : "PUT",
|
if (emoji instanceof Emoji) {
|
||||||
headers: this.headers,
|
reactiontxt = emoji.id;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emoji;
|
reactiontxt = encodeURIComponent(emoji);
|
||||||
}
|
}
|
||||||
|
fetch(`${this.info.api}/channels/${this.channel.id}/messages/${this.id}/reactions/${reactiontxt}/@me`, {
|
||||||
|
method: remove ? "DELETE" : "PUT",
|
||||||
|
headers: this.headers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
giveData(messagejson) {
|
giveData(messagejson) {
|
||||||
for (const thing of Object.keys(messagejson)) {
|
for (const thing of Object.keys(messagejson)) {
|
||||||
|
@ -383,7 +385,9 @@ class Message {
|
||||||
reaction.classList.add("meReacted");
|
reaction.classList.add("meReacted");
|
||||||
}
|
}
|
||||||
let emoji;
|
let emoji;
|
||||||
if (thing.emoji.id) {
|
if (thing.emoji.id || /\d{17,21}/.test(thing.emoji.name)) {
|
||||||
|
if (/\d{17,21}/.test(thing.emoji.name))
|
||||||
|
thing.emoji.id = thing.emoji.name; //Should stop being a thing once the server fixes this bug
|
||||||
const emo = new Emoji(thing.emoji, this.guild);
|
const emo = new Emoji(thing.emoji, this.guild);
|
||||||
emoji = emo.getHTML(false);
|
emoji = emo.getHTML(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ class Emoji{
|
||||||
Emoji.decodeEmojiList(e);
|
Emoji.decodeEmojiList(e);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
static async emojiPicker(x:number,y:number):Promise<Emoji|string>{
|
static async emojiPicker(x:number,y:number, localuser:Localuser):Promise<Emoji|string>{
|
||||||
let res:(r:Emoji|string)=>void;
|
let res:(r:Emoji|string)=>void;
|
||||||
const promise:Promise<Emoji|string>=new Promise((r)=>{res=r;})
|
const promise:Promise<Emoji|string>=new Promise((r)=>{res=r;})
|
||||||
const menu=document.createElement("div");
|
const menu=document.createElement("div");
|
||||||
|
@ -118,6 +118,65 @@ class Emoji{
|
||||||
menu.style.top=y+"px";
|
menu.style.top=y+"px";
|
||||||
menu.style.left=x+"px";
|
menu.style.left=x+"px";
|
||||||
|
|
||||||
|
const title=document.createElement("h2");
|
||||||
|
title.textContent=Emoji.emojis[0].name;
|
||||||
|
title.classList.add("emojiTitle");
|
||||||
|
menu.append(title);
|
||||||
|
console.log("menu :3");
|
||||||
|
const selection=document.createElement("div");
|
||||||
|
selection.classList.add("flexltr","dontshrink","emojirow");
|
||||||
|
console.log("menu :3");
|
||||||
|
const body=document.createElement("div");
|
||||||
|
body.classList.add("emojiBody");
|
||||||
|
|
||||||
|
let isFirst = true;
|
||||||
|
localuser.guilds.filter(guild => guild.id != "@me" && guild.emojis.length > 0).forEach(guild => {
|
||||||
|
const select = document.createElement("div")
|
||||||
|
select.classList.add("emojiSelect")
|
||||||
|
|
||||||
|
if (guild.properties.icon) {
|
||||||
|
const img = document.createElement("img")
|
||||||
|
img.classList.add("pfp", "servericon", "emoji-server")
|
||||||
|
img.crossOrigin = "anonymous"
|
||||||
|
img.src = localuser.info.cdn + "/icons/" + guild.properties.id + "/" + guild.properties.icon + ".png?size=48"
|
||||||
|
img.alt = "Server: " + guild.properties.name
|
||||||
|
select.appendChild(img)
|
||||||
|
} else {
|
||||||
|
const div = document.createElement("span")
|
||||||
|
div.textContent = guild.properties.name.replace(/'s /g, " ").replace(/\w+/g, word => word[0]).replace(/\s/g, "")
|
||||||
|
select.append(div)
|
||||||
|
}
|
||||||
|
|
||||||
|
selection.append(select)
|
||||||
|
|
||||||
|
const clickEvent = () => {
|
||||||
|
title.textContent = guild.properties.name
|
||||||
|
body.innerHTML = ""
|
||||||
|
for (const emojit of guild.emojis) {
|
||||||
|
const emojiElem = document.createElement("div")
|
||||||
|
emojiElem.classList.add("emojiSelect")
|
||||||
|
|
||||||
|
const emojiClass = new Emoji({
|
||||||
|
id: emojit.id,
|
||||||
|
name: emojit.name,
|
||||||
|
animated: emojit.animated
|
||||||
|
},localuser)
|
||||||
|
emojiElem.append(emojiClass.getHTML())
|
||||||
|
body.append(emojiElem)
|
||||||
|
|
||||||
|
emojiElem.addEventListener("click", () => {
|
||||||
|
res(emojiClass)
|
||||||
|
Contextmenu.currentmenu.remove()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
select.addEventListener("click", clickEvent)
|
||||||
|
if (isFirst) {
|
||||||
|
clickEvent()
|
||||||
|
isFirst = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
if(Contextmenu.currentmenu!=""){
|
if(Contextmenu.currentmenu!=""){
|
||||||
|
@ -128,16 +187,7 @@ class Emoji{
|
||||||
Contextmenu.keepOnScreen(menu);
|
Contextmenu.keepOnScreen(menu);
|
||||||
},10)
|
},10)
|
||||||
|
|
||||||
const title=document.createElement("h2");
|
|
||||||
title.textContent=Emoji.emojis[0].name;
|
|
||||||
title.classList.add("emojiTitle");
|
|
||||||
menu.append(title);
|
|
||||||
console.log("menu :3");
|
|
||||||
const selection=document.createElement("div");
|
|
||||||
selection.classList.add("flexltr","dontshrink");
|
|
||||||
console.log("menu :3");
|
|
||||||
const body=document.createElement("div");
|
|
||||||
body.classList.add("emojiBody");
|
|
||||||
let i=0;
|
let i=0;
|
||||||
for(const thing of Emoji.emojis){
|
for(const thing of Emoji.emojis){
|
||||||
const select=document.createElement("div");
|
const select=document.createElement("div");
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {Member} from "./member.js";
|
||||||
import {Settings,RoleList} from "./settings.js";
|
import {Settings,RoleList} from "./settings.js";
|
||||||
import {Permissions} from "./permissions.js";
|
import {Permissions} from "./permissions.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
import { channeljson, guildjson } from "./jsontypes.js";
|
import { channeljson, guildjson, emojijson } from "./jsontypes.js";
|
||||||
class Guild{
|
class Guild{
|
||||||
owner:Localuser;
|
owner:Localuser;
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
|
@ -24,6 +24,7 @@ class Guild{
|
||||||
parent_id:string;
|
parent_id:string;
|
||||||
member:Member;
|
member:Member;
|
||||||
html:HTMLElement;
|
html:HTMLElement;
|
||||||
|
emojis:emojijson[];
|
||||||
get id(){
|
get id(){
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +85,7 @@ class Guild{
|
||||||
if(json===-1){
|
if(json===-1){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.emojis = json.emojis
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
|
|
|
@ -156,12 +156,17 @@ type memberjson= {
|
||||||
pending: boolean,
|
pending: boolean,
|
||||||
last_message_id?: boolean//What???
|
last_message_id?: boolean//What???
|
||||||
}
|
}
|
||||||
|
type emojijson={
|
||||||
|
name:string,
|
||||||
|
id?:string,
|
||||||
|
animated?:boolean
|
||||||
|
}
|
||||||
|
|
||||||
type guildjson={
|
type guildjson={
|
||||||
application_command_counts: {[key:string]:number},
|
application_command_counts: {[key:string]:number},
|
||||||
channels: channeljson[],
|
channels: channeljson[],
|
||||||
data_mode: string,
|
data_mode: string,
|
||||||
emojis: [],
|
emojis: emojijson[],
|
||||||
guild_scheduled_events: [],
|
guild_scheduled_events: [],
|
||||||
id: string,
|
id: string,
|
||||||
large: boolean,
|
large: boolean,
|
||||||
|
@ -274,11 +279,7 @@ type messagejson={
|
||||||
embeds: embedjson[],
|
embeds: embedjson[],
|
||||||
reactions: {
|
reactions: {
|
||||||
count:number,
|
count:number,
|
||||||
emoji:{
|
emoji:emojijson,//very likely needs expanding
|
||||||
name:string,
|
|
||||||
id?:string,
|
|
||||||
animated?:boolean
|
|
||||||
},//very likely needs expanding
|
|
||||||
me:boolean,
|
me:boolean,
|
||||||
}[],
|
}[],
|
||||||
nonce: string,
|
nonce: string,
|
||||||
|
@ -326,4 +327,4 @@ type embedjson={
|
||||||
name:string,
|
name:string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson,filejson,embedjson};
|
export {readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson,filejson,embedjson,emojijson};
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Message{
|
||||||
navigator.clipboard.writeText(this.id);
|
navigator.clipboard.writeText(this.id);
|
||||||
});
|
});
|
||||||
Message.contextmenu.addsubmenu("Add reaction",function(this:Message,e){
|
Message.contextmenu.addsubmenu("Add reaction",function(this:Message,e){
|
||||||
Emoji.emojiPicker(e.x,e.y).then(_=>{
|
Emoji.emojiPicker(e.x,e.y,this.localuser).then(_=>{
|
||||||
console.log(_,":3")
|
console.log(_,":3")
|
||||||
this.reactionToggle(_);
|
this.reactionToggle(_);
|
||||||
});
|
});
|
||||||
|
@ -77,21 +77,24 @@ class Message{
|
||||||
}
|
}
|
||||||
reactionToggle(emoji:string|Emoji){
|
reactionToggle(emoji:string|Emoji){
|
||||||
|
|
||||||
if(typeof emoji === "string"){
|
let remove = false
|
||||||
let remove=false;
|
|
||||||
for (const thing of this.reactions) {
|
for (const thing of this.reactions) {
|
||||||
if (thing.emoji.name === emoji) {
|
if (thing.emoji.name === emoji) {
|
||||||
remove=thing.me;
|
remove = thing.me
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
fetch(this.info.api+ "/channels/"+this.channel.id+"/messages/"+this.id+"/reactions/"+encodeURIComponent(emoji)+"/@me",{
|
let reactiontxt:string;
|
||||||
method:remove?"DELETE":"PUT",
|
if(emoji instanceof Emoji){
|
||||||
headers:this.headers,
|
reactiontxt=emoji.id;
|
||||||
})
|
|
||||||
}else{
|
}else{
|
||||||
emoji
|
reactiontxt=encodeURIComponent(emoji);
|
||||||
}
|
}
|
||||||
|
fetch(`${this.info.api}/channels/${this.channel.id}/messages/${this.id}/reactions/${reactiontxt}/@me`, {
|
||||||
|
method: remove ? "DELETE" : "PUT",
|
||||||
|
headers: this.headers
|
||||||
|
})
|
||||||
}
|
}
|
||||||
giveData(messagejson:messagejson){
|
giveData(messagejson:messagejson){
|
||||||
for(const thing of Object.keys(messagejson)){
|
for(const thing of Object.keys(messagejson)){
|
||||||
|
@ -387,7 +390,8 @@ class Message{
|
||||||
reaction.classList.add("meReacted")
|
reaction.classList.add("meReacted")
|
||||||
}
|
}
|
||||||
let emoji:HTMLElement;
|
let emoji:HTMLElement;
|
||||||
if(thing.emoji.id){
|
if (thing.emoji.id || /\d{17,21}/.test(thing.emoji.name)) {
|
||||||
|
if (/\d{17,21}/.test(thing.emoji.name)) thing.emoji.id=thing.emoji.name;//Should stop being a thing once the server fixes this bug
|
||||||
const emo=new Emoji(thing.emoji as {name:string,id:string,animated:boolean},this.guild);
|
const emo=new Emoji(thing.emoji as {name:string,id:string,animated:boolean},this.guild);
|
||||||
emoji=emo.getHTML(false);
|
emoji=emo.getHTML(false);
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -1594,6 +1594,7 @@ form div{
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
border:solid var(--black) .03in;
|
border:solid var(--black) .03in;
|
||||||
flex-shrink:0;
|
flex-shrink:0;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
.emojiTitle{
|
.emojiTitle{
|
||||||
padding: .03in;
|
padding: .03in;
|
||||||
|
@ -1607,7 +1608,7 @@ form div{
|
||||||
display:flex;
|
display:flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-content: stretch;
|
align-content: flex-start;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
/* height: 100%; */
|
/* height: 100%; */
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
@ -1721,3 +1722,10 @@ form div{
|
||||||
width:.225in;
|
width:.225in;
|
||||||
margin:.05in;
|
margin:.05in;
|
||||||
}
|
}
|
||||||
|
.emojiSelect > .emoji-server {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
.emojirow{
|
||||||
|
flex-grow:0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue