Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce need for 3rd parties to modify as much #52

Closed
cletusc opened this issue Jul 2, 2014 · 3 comments
Closed

Reduce need for 3rd parties to modify as much #52

cletusc opened this issue Jul 2, 2014 · 3 comments

Comments

@cletusc
Copy link
Owner

cletusc commented Jul 2, 2014

BetterTTV is modifying the script a bit for their uses and I'd like to reduce the need for it. Here is a diff of the changes they make to the script, as of v0.5.18:

--- our-script.user.js
+++ betterttv-script.user.js
@@ -1,4 +1,3 @@
-// ==UserScript==
 // @name Twitch Chat Emotes
 // @namespace #Cletus
 // @version 0.5.18
@@ -14,7 +13,6 @@
 // @include http://*.twitch.tv/*
 // @exclude http://api.twitch.tv/*
 // @exclude http://*.twitch.tv/*/profile*
-// ==/UserScript==

 // Start wrapper.
 (function wrapper(window, injectNeeded, undefined) {
@@ -184,33 +182,35 @@
        createMenuElements();
        addStyle(templates.styles());
        bindListeners();
-       showNews();
+       //showNews();

        // Get active subscriptions.
        window.Twitch.api.get("/api/users/:login/tickets").done(function (api) {
            debug(api, 'Response from `/api/user/:login/tickets`.', true);
            api.tickets.forEach(function (ticket) {
                // Get subscriptions with emotes.
-               if (ticket.product.emoticons && ticket.product.emoticons.length) {
-                   var badge = ticket.product.features.badge,
-                       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
-                       };
-                   });
-               }
+               });
            });
        });
    }
@@ -510,12 +510,15 @@
                if (emotes.subscriptions.emotes[emote.text] && image.url === emotes.subscriptions.emotes[emote.text].url) {
                    emote.image = image;
                    return true;
+               } else if (emote.channel === "Night" && Twitch.user.isLoggedIn() && window.BetterTTV.chat.helpers.getEmotes(Twitch.user.login()).indexOf('night') !== -1) {
+                   emote.image = image;
+                   return true;
                }
            });
            emote.image = emote.image || defaultImage;
            // Fix missing image.html on new layout.
            if (emote.image && !emote.image.html) {
-               emote.image.html = '<img src="' + emote.image.url + '">';
+               emote.image.html = '<img src="' + emote.image.url + '"'+((emote.image.width>=32)?' width="32" height="'+(emote.image.height/(emote.image.width/32))+'"':'')+'>';
            }

            // Only add the emote if there is a URL.
@@ -637,14 +640,7 @@
        if (showHeader) {
            if (emote.channel && emote.channel !== 'Twitch Turbo') {
                var badge = emotes.subscriptions.badges[emote.channel] || emote.badge;
-               // Add notice about addon emotes.
-               if (!emotes.subscriptions.badges[emote.channel] && !elemEmoteMenu.find('.group-header.addon-emotes-header').length) {
-                   container.append(
-                       $(templates.emoteGroupHeader({
-                           isAddonHeader: true
-                       }))
-                   );
-               }
+
                if (!elemEmoteMenu.find('.group-header[data-emote-channel="' + emote.channel + '"]').length) {
                    container.append(
                        $(templates.emoteGroupHeader({
@@ -920,4 +916,4 @@
    }

 // End wrapper.
-})(this.unsafeWindow || window, window.chrome ? true : false);
+})(this.unsafeWindow || window, window.chrome ? true : false);

Basically I am seeing the following:

  • Removes userscript tags; would be eliminated by using the minified version. @night mentioned this may be an issue with Chrome thinking it was a userscript while in content scope. This is a wontfix as it is required. The minified version should be used instead.
  • Removes news checks; will be eliminated by Move news items into the menu #43
  • Makes additional API call for channel's display name; will be eliminated by either making the call and caching it (new storage system for ease-of-use), or by making the all lowercase into first-letter uppercase just as Twitch does in default chat. My vote: undecided
  • Adds additional check for @night's channel. From my understanding after talking to @night, this is used for his own channels non-Twitch donation system. My vote: look into how Night is handling it and suggest a better way of doing it.
  • Forces emote image size to 32x32 max. This isn't needed at all, but would be further eliminated by Emotes are flickering on initial opening of menu #40
  • Removes the "addon emotes" header that was added in Allow custom sorting of emote groups. #28. My vote: definite wontfix unless @night can convince me otherwise.

Those watching the repo, please provide your input on the above points.

@night
Copy link

night commented Jul 2, 2014

For an addon like BetterTTV, it will probably not be possible to reduce the need for modification.

cletusc added a commit that referenced this issue Jul 16, 2014
Fixes #50 and fixes #24.

This also assists with #52 in that an emote with special set will be
detected. This may be a bit buggy depending on how the emote sets are
actually _set_.
@cletusc
Copy link
Owner Author

cletusc commented Jul 30, 2014

Updated diff of v0.6.3:

--- our-script.user.js
+++ betterttv-script.user.js
@@ -1,4 +1,3 @@
-// ==UserScript==
 // @name Twitch Chat Emotes
 // @namespace #Cletus
 // @version 0.6.3
@@ -15,7 +14,6 @@
 // @exclude http://api.twitch.tv/*
 // @exclude http://chatdepot.twitch.tv/*
 // @exclude http://*.twitch.tv/*/profile*
-// ==/UserScript==

 // This script was generated using an automated build script.
 // See project build guide linked at http://cletusc.github.io/Userscript--Twitch-Chat-Emotes/ for more info.
@@ -234,26 +232,28 @@
    ).done(function (api) {
        api.tickets.forEach(function (ticket) {
            // Get subscriptions with emotes.
-           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
-                   };
-               });
-           }
+           });
        });
    });
 }
@@ -557,6 +557,10 @@
                emote.image = image;
                return true;
            }
+           if (emote.channel === "Night" && window.Twitch.user.isLoggedIn() && window.BetterTTV.chat.helpers.getEmotes(window.Twitch.user.login()).indexOf('night') !== -1) {
+               emote.image = image;
+               return true;
+           }
        });
        emote.image = emote.image || defaultImage;
        // Fix missing image.html on new layout.
@@ -684,13 +688,13 @@
        if (emote.channel && emote.channel !== 'Twitch Turbo') {
            var badge = emotes.subscriptions.badges[emote.channel] || emote.badge;
            // Add notice about addon emotes.
-           if (!emotes.subscriptions.badges[emote.channel] && !elements.menu.find('.group-header.addon-emotes-header').length) {
+           /*if (!emotes.subscriptions.badges[emote.channel] && !elements.menu.find('.group-header.addon-emotes-header').length) {
                container.append(
                    $(templates.emoteGroupHeader({
                        isAddonHeader: true
                    }))
                );
-           }
+           }*/
            if (!elements.menu.find('.group-header[data-emote-channel="' + emote.channel + '"]').length) {
                container.append(
                    $(templates.emoteGroupHeader({
@@ -833,4 +837,4 @@
    }

 // End wrapper.
-})(this.unsafeWindow || window, window.chrome ? true : false);
+})(this.unsafeWindow || window, window.chrome ? true : false);
  • Removes userscript tags. Works for me, unable to reproduce on Firefox/Chrome/Opera using this gist on any channel, on GM or TM. @night can you take a look at this again--doesn't look like you need to remove those tags.
  • Makes an additional call for display name. Will implement in Use sub channel's display name #60.
  • Adds check for Night's channel. Will be fixed by Turbo emoticons should be added #50 as I will be checking the if the emote's emoticon_set is found in the user's sets. @night, I recommend only adding those emotes to the page if they are on your channel and making sure the emote's emoticon_set is night and that night is somewhere in the user's sets; the menu will do the rest once Turbo emoticons should be added #50 is done. Edit: Looked into this even further; BTTV doesn't add night to the public emote sets (it merges it's own internal emote sets), therefore we can't see them. We can allow forcing an emote to show if emote.hidden === false, which would allow @night to move that logic into BTTV.
  • Removes addon header. Voting wontfix, but may possibly be removed once Allow hiding emotes through GUI #26 is implemented Users have the right to know that an emote can't be seen unless other users also have that addon that added that emote, e.g. BetterTTV or FrankerFaceZ.

Edit: see bolded edit in the adds check for Night's channel section above.

cletusc added a commit that referenced this issue Oct 1, 2014
...styling on third party emotes. In conjunction with
c95f412 this resolves part of #52.
@cletusc
Copy link
Owner Author

cletusc commented Oct 1, 2014

I am closing this, I think it is mostly taken care of on my end.

  • Userscript tags shouldn't need to be removed as per the above gist.
  • Use sub channel's display name #60 will handle the display names.
  • emote.hidden can be set to false to force the emote to show, as of ed37c82. This allows third parties to use their own logic on their end.
  • 2fd87d6 and c95f412 reworks how the addon header works. Removes the actual header and instead has "from third party addon" in the hover-text of each affected emote. This will apply on any third party emote, not just the stuff that gets grouped.

@night if there is anything else that you may normally modify, let me know and I'll reopen this issue. I want to reduce as much work as possible. This should basically be a drop-in addon.

@cletusc cletusc closed this as completed Oct 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants