forked from Jiiks/BetterDiscordApp
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from JsSucks/emotes-and-databases
Emotes and databases
- Loading branch information
Showing
12 changed files
with
346 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* BetterDiscord Autocomplete Component | ||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks | ||
* All rights reserved. | ||
* https://betterdiscord.net | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
<template> | ||
<div class="bd-autocomplete"> | ||
<div class="bd-autocomplete-inner"> | ||
<div class="bd-autocompleteRow"> | ||
<div class="bd-autocompleteSelector"> | ||
<div class="bd-autocompleteTitle"> | ||
Emotes Matching: | ||
<strong>Kappa</strong> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
import EmoteModule from '../../../builtin/Emotemodule.js'; | ||
export default { | ||
props: ['title', 'emotes'], | ||
beforeMount() { | ||
console.log(EmoteModule); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.bd-autocomplete { | ||
border-radius: 5px 5px 0 0; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
z-index: 3; | ||
bottom: 100%; | ||
left: 0; | ||
position: absolute; | ||
right: 0; | ||
background-color: #2f3136; | ||
|
||
.bd-autocomplete-inner { | ||
padding-bottom: 8px; | ||
white-space: nowrap; | ||
|
||
.bd-autocompleteRow { | ||
padding: 0 8px; | ||
font-size: 14px; | ||
line-height: 16px; | ||
|
||
.bd-autocompleteSelector { | ||
border-radius: 3px; | ||
padding: 8px; | ||
|
||
&.bd-selectable { | ||
cursor: pointer; | ||
} | ||
|
||
&.bd-selected { | ||
background-color: #36393f; | ||
} | ||
|
||
.bd-autocompleteTitle { | ||
color: #72767d; | ||
padding: 4px 0; | ||
text-transform: uppercase; | ||
font-weight: 600; | ||
line-height: 16px; | ||
font-size: 12px; | ||
|
||
strong { | ||
color: #fff; | ||
text-transform: none; | ||
font-weight: 500; | ||
} | ||
} | ||
|
||
.bd-autocompleteField { | ||
display: flex; | ||
flex: 1 1 auto; | ||
color: #f6f6f7; | ||
min-height: 16px; | ||
-webkit-box-direction: normal; | ||
-webkit-box-orient: horizontal; | ||
flex-direction: row; | ||
flex-wrap: nowrap; | ||
-webkit-box-pack: start; | ||
justify-content: flex-start; | ||
-webkit-box-align: center; | ||
align-items: center; | ||
|
||
img { | ||
min-width: 16px; | ||
width: 16px; | ||
} | ||
|
||
div { | ||
margin-left: 8px; | ||
color: #f6f6f7; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* BetterDiscord Autocomplete Component | ||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks | ||
* All rights reserved. | ||
* https://betterdiscord.net | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
<template> | ||
<div class="bd-autocomplete"> | ||
<div v-if="emotes && emotes.length" class="bd-autocomplete-inner"> | ||
<div class="bd-autocompleteRow"> | ||
<div class="bd-autocompleteSelector"> | ||
<div class="bd-autocompleteTitle"> | ||
Emotes Matching: | ||
<strong>{{title}}</strong> | ||
</div> | ||
</div> | ||
</div> | ||
<div v-for="(emote, index) in emotes" class="bd-autocompleteRow" :key="emote.id"> | ||
<div class="bd-autocompleteSelector bd-selectable" :class="{'bd-selected': index === selectedIndex}" @mouseover="() => { selected = emote.id }" @click="() => inject(emote)"> | ||
<div class="bd-autocompleteField"> | ||
<img :src="getEmoteSrc(emote)"/> | ||
<div>{{emote.id}}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
import { EmoteModule } from 'builtin'; | ||
import { Events } from 'modules'; | ||
import { DOM } from 'ui'; | ||
export default { | ||
data() { | ||
return { | ||
emotes: [], | ||
title: '', | ||
selIndex: 0, | ||
selected: '', | ||
open: false, | ||
selectedIndex: 0, | ||
sterm: '' | ||
} | ||
}, | ||
props: ['initial'], | ||
beforeMount() { | ||
// this.emotes = EmoteModule.filter(new RegExp(this.initial, 'i'), 10); | ||
// this.open = this.emotes.length; | ||
}, | ||
created() { | ||
window.addEventListener('keydown', this.prevents); | ||
const ta = document.querySelector('.chat textarea'); | ||
ta.addEventListener('keydown', this.setCaret); | ||
ta.addEventListener('keyup', this.searchEmotes); | ||
}, | ||
destroyed() { | ||
window.removeEventListener('keydown', this.prevents); | ||
const ta = document.querySelector('.chat textarea'); | ||
ta.removeEventListener('keydown', this.setCaret); | ||
ta.removeEventListener('keyup', this.searchEmotes); | ||
}, | ||
methods: { | ||
prevents(e) { | ||
if (!this.open) return; | ||
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp' && e.key !== 'Tab') return; | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}, | ||
setCaret(e) { | ||
this.caret = e.target.selectionEnd; | ||
}, | ||
getEmoteSrc(emote) { | ||
let { id, value } = emote; | ||
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) { | ||
if (e.key === 'ArrowDown' && this.open && this.caret) { | ||
this.selectedIndex = (this.selectedIndex + 1) >= 10 ? 0 : this.selectedIndex + 1; | ||
return; | ||
} else if (e.key === 'ArrowUp' && this.open && this.caret) { | ||
this.selectedIndex = (this.selectedIndex - 1) < 0 ? 9 : this.selectedIndex - 1; | ||
return; | ||
} | ||
if (e.key === 'Tab' && this.open && this.caret) { | ||
const selected = this.emotes[this.selectedIndex]; | ||
if (!selected) return; | ||
this.inject(selected); | ||
return; | ||
} | ||
const se = e.target.selectionEnd; | ||
this.sterm = e.target.value.substr(0, se).split(' ').slice(-1).pop(); | ||
if (this.sterm.length < 3) { | ||
this.emotes = []; | ||
this.selected = ''; | ||
this.selectedIndex = 0; | ||
return; | ||
} | ||
this.title = this.sterm; | ||
this.emotes = EmoteModule.filter(new RegExp(this.sterm, ''), 10); | ||
this.open = this.emotes.length; | ||
}, | ||
inject(emote) { | ||
const ta = document.querySelector('.chat textarea'); | ||
if (!ta) return; | ||
const currentText = document.querySelector('.chat textarea').value; | ||
const se = ta.selectionEnd; | ||
const split = currentText.substr(0, se).split(' '); | ||
split.pop(); | ||
split.push(`:${emote.id}:`); | ||
const join = split.join(' '); | ||
const rest = currentText.substr(se, currentText.length); | ||
DOM.manip.setText(join + ' ' + rest, false); | ||
this.emotes = []; | ||
this.open = false; | ||
this.selectedIndex = 0; | ||
this.selected = ''; | ||
ta.selectionEnd = ta.selectionStart = se + `:${emote.id}:`.length - this.title.length; | ||
} | ||
} | ||
} | ||
</script> |
Oops, something went wrong.