cletusc / Userscript--Twitch-Chat-Emotes

Adds a button to Twitch that allows you to "click-to-insert" an emote.
http://cletusc.github.io/Userscript--Twitch-Chat-Emotes/
MIT License
36 stars 20 forks source link

Use sub channel's display name #60

Closed cletusc closed 9 years ago

cletusc commented 10 years ago

Initially from #52, with a poll pushing me to add this. Results at the time of this post are:

Depends on #59 as I don't want to make excessive API calls; cache display name for 24 hours.

BTTV's implementation in #52:

-           if (ticket.product.emoticons && ticket.product.emoticons.length) {
-               var badge = ticket.product.features.badge;
-               var channel = ticket.product.owner_name;
-               // Add channel badges.
-               if (badge) {
-                   badge = 'http://static-cdn.jtvnw.net/jtv_user_pictures/' + [badge.prefix, badge.owner, badge.type, badge.uid, badge.sizes[0]].join('-') + '.' + badge.format;
+           window.Twitch.api.get("users/"+(ticket.product.owner_name || 'turbo')).done(function(owner) {
+               if (ticket.product.emoticons && ticket.product.emoticons.length) {
+                   var badge = ticket.product.features.badge,
+                       channel = owner.display_name;
+                   // Add channel badges.
+                   if (badge) {
+                       badge = 'http://static-cdn.jtvnw.net/jtv_user_pictures/' + [badge.prefix, badge.owner, badge.type, badge.uid, badge.sizes[0]].join('-') + '.' + badge.format;
+                   }
+                   else {
+                       badge = 'https://static-cdn.jtvnw.net/jtv_user_pictures/subscriber-star.png';
+                   }
+                   emotes.subscriptions.badges[channel] = badge;
+                   
+                   // Add emotes channel.
+                   ticket.product.emoticons.forEach(function (emote) {
+                       emotes.subscriptions.emotes[getEmoteFromRegEx(new RegExp(emote.regex))] = {
+                           channel: channel,
+                           url: emote.url
+                       };
+                   });
                }
-               else {
-                   badge = 'https://static-cdn.jtvnw.net/jtv_user_pictures/subscriber-star.png';
-               }
-               emotes.subscriptions.badges[channel] = badge;
-               
-               // Add emotes channel.
-               ticket.product.emoticons.forEach(function (emote) {
-                   emotes.subscriptions.emotes[getEmoteFromRegEx(new RegExp(emote.regex))] = {
-                       channel: channel,
-                       url: emote.url
-                   };
-               });
-           }
+           });