fix emote menu

This commit is contained in:
Zack Rauen 2019-06-28 02:19:36 -04:00
parent bff88ea865
commit ec46a237b7
6 changed files with 21 additions and 14 deletions

File diff suppressed because one or more lines are too long

2
js/main.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,7 @@
// Export these two first because they add settings/panels
export {default as EmoteModule} from "./emotes";
export {default as CustomCSS} from "./customcss";
export {default as VoiceMode} from "./voicemode"; export {default as VoiceMode} from "./voicemode";
export {default as ClassNormalizer} from "./classnormalizer"; export {default as ClassNormalizer} from "./classnormalizer";
export {default as DeveloperMode} from "./developermode"; export {default as DeveloperMode} from "./developermode";
@ -9,6 +13,4 @@ export {default as ColoredText} from "./coloredtext";
export {default as VoiceDisconnect} from "./voicedisconnect"; export {default as VoiceDisconnect} from "./voicedisconnect";
export {default as EmoteMenu} from "./emotemenu"; export {default as EmoteMenu} from "./emotemenu";
export {default as EmoteAutocaps} from "./emoteautocaps"; export {default as EmoteAutocaps} from "./emoteautocaps";
export {default as EmoteModule} from "./emotes";
export {default as WindowPrefs} from "./windowprefs"; export {default as WindowPrefs} from "./windowprefs";
export {default as CustomCSS} from "./customcss";

View File

@ -75,6 +75,7 @@ export default new class EmoteMenu extends Builtin {
this.hideEmojiCancel = this.registerSetting(this.hideEmojisID, this.enableHideEmojis, this.disableHideEmojis); this.hideEmojiCancel = this.registerSetting(this.hideEmojisID, this.enableHideEmojis, this.disableHideEmojis);
if (this.hideEmojis) this.enableHideEmojis(); if (this.hideEmojis) this.enableHideEmojis();
if (EmoteModule.emotesLoaded) this.updateTwitchEmotes(); if (EmoteModule.emotesLoaded) this.updateTwitchEmotes();
this.updateFavorites();
Events.on("emotes-loaded", this.updateTwitchEmotes); Events.on("emotes-loaded", this.updateTwitchEmotes);
} }
@ -176,7 +177,7 @@ export default new class EmoteMenu extends Builtin {
while (this.teContainerInner.firstChild) this.teContainerInner.firstChild.remove(); while (this.teContainerInner.firstChild) this.teContainerInner.firstChild.remove();
for (const emote in EmoteModule.getCategory("TwitchGlobal")) { for (const emote in EmoteModule.getCategory("TwitchGlobal")) {
if (!EmoteModule.getCategory("TwitchGlobal").hasOwnProperty(emote)) continue; if (!EmoteModule.getCategory("TwitchGlobal").hasOwnProperty(emote)) continue;
const url = EmoteModule.getCategory("TwitchGlobal")[emote]; const url = EmoteModule.getUrl("TwitchGlobal", emote);
const emoteElement = makeEmote(emote, url, {onClick: this.insertEmote.bind(this, emote)}); const emoteElement = makeEmote(emote, url, {onClick: this.insertEmote.bind(this, emote)});
this.teContainerInner.append(emoteElement); this.teContainerInner.append(emoteElement);
} }

View File

@ -66,12 +66,14 @@ export default new class EmoteModule extends Builtin {
get BTTV2() {return Emotes.BTTV2;} get BTTV2() {return Emotes.BTTV2;}
get blacklist() {return blacklist;} get blacklist() {return blacklist;}
get favorites() {return this.favoriteEmotes;} get favorites() {return this.favoriteEmotes;}
getUrl(category, name) {return EmoteURLs[category].format({id: Emotes[category][name]});}
getCategory(category) {return Emotes[category];} getCategory(category) {return Emotes[category];}
getRemoteFile(category) {return Utilities.repoUrl(`data/emotes/${category.toLowerCase()}.json`);} getRemoteFile(category) {return Utilities.repoUrl(`data/emotes/${category.toLowerCase()}.json`);}
initialize() { initialize() {
super.initialize(); super.initialize();
window.emoteModule = this;
this.favoriteEmotes = {}; this.favoriteEmotes = {};
const fe = DataStore.getBDData("bdfavemotes"); const fe = DataStore.getBDData("bdfavemotes");
if (fe !== "" && fe !== null) this.favoriteEmotes = JSON.parse(window.atob(fe)); if (fe !== "" && fe !== null) this.favoriteEmotes = JSON.parse(window.atob(fe));
@ -149,7 +151,7 @@ export default new class EmoteModule extends Builtin {
let emoteOverride = emoteModifier.slice(0); let emoteOverride = emoteModifier.slice(0);
if (emoteName.length < 4 || blacklist.includes(emoteName)) continue; if (emoteName.length < 4 || blacklist.includes(emoteName)) continue;
if (!modifiers.includes(emoteModifier) || !Settings.get(this.category, "general", "modifiers")) emoteModifier = ""; if (!modifiers.includes(emoteModifier) || !Settings.get("emotes", "general", "modifiers")) emoteModifier = "";
if (!overrides.includes(emoteOverride)) emoteOverride = ""; if (!overrides.includes(emoteOverride)) emoteOverride = "";
else emoteModifier = emoteOverride; else emoteModifier = emoteOverride;
@ -166,13 +168,13 @@ export default new class EmoteModule extends Builtin {
if (Emotes.FrankerFaceZ[emoteName]) current = "FrankerFaceZ"; if (Emotes.FrankerFaceZ[emoteName]) current = "FrankerFaceZ";
} }
if (!Emotes[current][emoteName] || !Settings.get(this.category, "categories", bdEmoteSettingIDs[current])) continue; if (!Emotes[current][emoteName] || !Settings.get("emotes", "categories", bdEmoteSettingIDs[current])) continue;
const results = nodes[n].match(new RegExp(`([\\s]|^)${Utilities.escape(emoteModifier ? emoteName + ":" + emoteModifier : emoteName)}([\\s]|$)`)); const results = nodes[n].match(new RegExp(`([\\s]|^)${Utilities.escape(emoteModifier ? emoteName + ":" + emoteModifier : emoteName)}([\\s]|$)`));
if (!results) continue; if (!results) continue;
const pre = nodes[n].substring(0, results.index + results[1].length); const pre = nodes[n].substring(0, results.index + results[1].length);
const post = nodes[n].substring(results.index + results[0].length - results[2].length); const post = nodes[n].substring(results.index + results[0].length - results[2].length);
nodes[n] = pre; nodes[n] = pre;
const emoteComponent = DiscordModules.React.createElement(BDEmote, {name: emoteName, url: Emotes[current][emoteName], modifier: emoteModifier, isFavorite: this.isFavorite(emoteName)}); const emoteComponent = DiscordModules.React.createElement(BDEmote, {name: emoteName, url: EmoteURLs[current].format({id: Emotes[current][emoteName]}), modifier: emoteModifier, isFavorite: this.isFavorite(emoteName)});
nodes.splice(n + 1, 0, post); nodes.splice(n + 1, 0, post);
nodes.splice(n + 1, 0, emoteComponent); nodes.splice(n + 1, 0, emoteComponent);
} }
@ -229,7 +231,7 @@ export default new class EmoteModule extends Builtin {
if (hasData) data = cachedData; if (hasData) data = cachedData;
} }
if (!data) data = await this.downloadEmotes(category); if (!data) data = await this.downloadEmotes(category);
for (const emote in data) data[emote] = EmoteURLs[category].format({id: data[emote]}); // for (const emote in data) data[emote] = EmoteURLs[category].format({id: data[emote]});
Object.assign(Emotes[category], data); Object.assign(Emotes[category], data);
} }

View File

@ -11,6 +11,8 @@ export default class BuiltinModule {
get id() {return "None";} get id() {return "None";}
async initialize() { async initialize() {
console.log("Initialize for " + this.name);
console.log(Settings.get(this.collection, this.category, this.id), this.collection, this.category, this.id);
if (Settings.get(this.collection, this.category, this.id)) await this.enable(); if (Settings.get(this.collection, this.category, this.id)) await this.enable();
Events.on("setting-updated", (collection, category, id, enabled) => { Events.on("setting-updated", (collection, category, id, enabled) => {
if (collection != this.collection || category !== this.category || id !== this.id) return; if (collection != this.collection || category !== this.category || id !== this.id) return;