diff --git a/package.json b/package.json index 8704d46e47..88ebf4f31b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "BetterTTV", "author": "Night", - "version": "7.0.17", + "version": "7.0.18", "description": "BetterTTV enhances Twitch with new features, bug fixes, and reduced clutter.", "main": "betterttv.js", "scripts": { diff --git a/src/modules/channel_emotes_tip/index.js b/src/modules/channel_emotes_tip/index.js index b2d0030924..d43cb69326 100644 --- a/src/modules/channel_emotes_tip/index.js +++ b/src/modules/channel_emotes_tip/index.js @@ -6,49 +6,57 @@ const html = require('../../utils/html'); class ChannelEmotesTipModule { constructor() { - this.sets = {}; - this.ids = {}; + this.ids = null; this.updateEmoteLists(); watcher.on('load.chat', () => this.checkEmoteSets()); } updateEmoteLists() { - api.get('emotes/sets') - .then(({sets}) => { - this.sets = sets; - }); - - api.get('emotes/ids') + api.get('twitch_emotes/ids') .then(({ids}) => { this.ids = ids; - }); + }) + .then(() => this.checkEmoteSets()); } getEmote(id, code) { - const channel = this.ids[id]; + if (!this.ids) return null; + + const name = this.ids[id]; + if (!name) return null; + return { - channel, - channelURL: `https://www.twitch.tv/${channel}`, + id, + code, + channel: { + name, + url: `https://www.twitch.tv/${name}` + }, balloon: ` ${html.escape(code)}
- ${channel ? `Channel: ${html.escape(channel)}` : ''} + ${name ? `Channel: ${html.escape(name)}` : ''} ` }; } checkEmoteSets() { + if (!this.ids) return null; + const room = twitch.getCurrentChat(); - if (!room || !room.product || !Array.isArray(room.product.emoticons)) return; + if (!room || !room.product) return; + + const {emoticons, name} = room.product; + if (!Array.isArray(emoticons) || !name) return; - const activeEmote = room.product.emoticons.find(emote => emote.state === 'active'); - if (!activeEmote || this.sets[activeEmote.emoticon_set]) { - debug.log(`Channel set exists for ${room.product.name}, no need to give a tip`); + const emote = emoticons.find(({state}) => state === 'active'); + if (!emote || this.ids[emote.id]) { + debug.log(`Channel set exists for ${name}, no need to give a tip`); return; } - api.post(`emotes/channel_tip/${room.product.name}`) - .then(() => debug.log(`Gave a channel tip for ${room.product.name}`)); + api.post('twitch_emotes/channel_tip', {body: {name}}) + .then(() => debug.log(`Gave a channel tip for ${name}`)); } } diff --git a/src/modules/chat/index.js b/src/modules/chat/index.js index 1b3107bf68..8bec1385a1 100644 --- a/src/modules/chat/index.js +++ b/src/modules/chat/index.js @@ -120,6 +120,7 @@ class ChatModule { } messageReplacer($message, user) { + const currentChannel = twitch.getCurrentChannel(); const tokens = $message.contents(); for (let i = 0; i < tokens.length; i++) { const node = tokens[i]; @@ -129,11 +130,11 @@ class ChatModule { if (!$image) continue; const code = $image.attr('alt'); const id = ($image.attr('src').split('emoticons/v1/')[1] || '').split('/')[0]; - const emoteChannel = channelEmotesTip.getEmote(id, code); - if (emoteChannel.channel) { - $emote.find('.balloon').css('text-align', 'center').html(emoteChannel.balloon); - if (emoteChannel.channelURL === window.location.href) continue; - $emote.on('click', () => window.open(emoteChannel.channelURL, '_blank')); + const emote = channelEmotesTip.getEmote(id, code); + if (emote) { + $emote.find('.balloon').css('text-align', 'center').html(emote.balloon); + if (!currentChannel || emote.channel.name === currentChannel.name) continue; + $emote.on('click', () => window.open(emote.channel.url, '_blank')); } continue; } diff --git a/src/modules/chat_deleted_messages/index.js b/src/modules/chat_deleted_messages/index.js index 60a685d022..d304e4839b 100644 --- a/src/modules/chat_deleted_messages/index.js +++ b/src/modules/chat_deleted_messages/index.js @@ -97,10 +97,11 @@ class ChatDeletedMessagesModule { const tmiRoom = currentChat.tmiRoom; const clearChatCallbacks = tmiRoom._events.clearchat; if (!clearChatCallbacks || !clearChatCallbacks.length) return; - const defaultClearChatCallback = clearChatCallbacks.find(c => c && c !== onClearChat); - if (defaultClearChatCallback && !tmiRoom._bttvClearChatMonkeyPatched) { - twitchClearChat = defaultClearChatCallback; - } + if (clearChatCallbacks.find(c => c && c === onClearChat)) return; + const defaultClearChatCallback = clearChatCallbacks.find(c => typeof c === 'function' && c !== onClearChat); + if (!defaultClearChatCallback || tmiRoom._bttvClearChatMonkeyPatched) return; + + twitchClearChat = defaultClearChatCallback; delete tmiRoom._events.clearchat; tmiRoom.on('clearchat', onClearChat); tmiRoom._bttvClearChatMonkeyPatched = true;