Emote autocomplete ui
This commit is contained in:
parent
523d226b91
commit
c59494f604
|
@ -99,4 +99,15 @@ export default class {
|
|||
const filtered = emotes.filter(emote => re.test(emote.id));
|
||||
return filtered.slice(0, 10);
|
||||
}
|
||||
|
||||
static filter(regex, limit) {
|
||||
let index = 0;
|
||||
return emotes.filter(emote => {
|
||||
if (index >= limit) return false;
|
||||
if (regex.test(emote.id)) {
|
||||
index++;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ export default class extends EventListener {
|
|||
{ id: 'server-switch', callback: this.manipAll },
|
||||
{ id: 'channel-switch', callback: this.manipAll },
|
||||
{ id: 'discord:MESSAGE_CREATE', callback: this.markupInjector },
|
||||
{ id: 'discord:MESSAGE_UPDATE', callback: this.markupInjector }
|
||||
{ id: 'discord:MESSAGE_UPDATE', callback: this.markupInjector },
|
||||
{ id: 'gkh:keyup', callback: this.injectAutocomplete }
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -198,7 +199,9 @@ export default class extends EventListener {
|
|||
return document.getElementById('app-mount');
|
||||
}
|
||||
|
||||
injectAutocomplete() {
|
||||
injectAutocomplete(e) {
|
||||
if (document.querySelector('.bd-autocomplete')) return;
|
||||
if (!e.target.closest('[class*=channelTextArea]')) return;
|
||||
const root = document.createElement('span');
|
||||
const parent = document.querySelector('[class*="channelTextArea"] > [class*="inner"]');
|
||||
if (!parent) return;
|
||||
|
@ -207,7 +210,7 @@ export default class extends EventListener {
|
|||
root,
|
||||
DOM.createElement('span'),
|
||||
{ Autocomplete },
|
||||
`<Autocomplete/>`,
|
||||
`<Autocomplete initial="${e.target.value}"/>`,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ export default class {
|
|||
server: TempApi.currentGuild,
|
||||
channel: TempApi.currentChannel
|
||||
};
|
||||
window.addEventListener('keyup', e => Events.emit('gkh:keyup', e));
|
||||
this.autoManip = new AutoManip();
|
||||
const defer = setInterval(() => {
|
||||
if (!this.profilePopupModule) return;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<div class="bd-autocompleteSelector">
|
||||
<div class="bd-autocompleteTitle">
|
||||
Emotes Matching:
|
||||
<strong>Kappa</strong>
|
||||
<strong>{{title || initial}}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -32,14 +32,23 @@
|
|||
</template>
|
||||
<script>
|
||||
import { EmoteModule } from 'builtin';
|
||||
import { Events } from 'modules';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
emotes: []
|
||||
emotes: [],
|
||||
title: null
|
||||
}
|
||||
},
|
||||
props: ['initial'],
|
||||
beforeMount() {
|
||||
this.emotes = EmoteModule.filterTest();
|
||||
this.emotes = EmoteModule.filter(new RegExp(this.initial, 'i'), 10);
|
||||
},
|
||||
created() {
|
||||
document.querySelector('.chat textarea').addEventListener('keyup', this.searchEmotes);
|
||||
},
|
||||
destroyed() {
|
||||
document.querySelector('.chat textarea').removeEventListener('keyup', this.searchEmotes);
|
||||
},
|
||||
methods: {
|
||||
getEmoteSrc(emote) {
|
||||
|
@ -47,6 +56,15 @@
|
|||
if (value.id) value = value.id;
|
||||
const uri = emote.type === 2 ? 'https://cdn.betterttv.net/emote/:id/1x' : emote.type === 1 ? 'https://cdn.frankerfacez.com/emoticon/:id/1' : 'https://static-cdn.jtvnw.net/emoticons/v1/:id/1.0';
|
||||
return uri.replace(':id', value);
|
||||
},
|
||||
searchEmotes(e) {
|
||||
const sterm = e.target.value.split(' ').slice(-1).pop();
|
||||
if (sterm.length < 3) {
|
||||
this.emotes = null;
|
||||
return;
|
||||
}
|
||||
this.title = sterm;
|
||||
this.emotes = EmoteModule.filter(new RegExp(sterm, 'i'), 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue