Picarto - Disable round, yellow emotes in chat

Replaces the yellow emotes in Picarto chat with their text-based counterparts (aka "normal" emotes).

当前为 2015-12-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Picarto - Disable round, yellow emotes in chat
  3. // @namespace http://github.com/SnowySailor
  4. // @include https://picarto.tv/*
  5. // @version 1
  6. // @grant none
  7. // @description Replaces the yellow emotes in Picarto chat with their text-based counterparts (aka "normal" emotes).
  8. // ==/UserScript==
  9. /*
  10. Created by SnowySailor - http://github.com/SnowySailor
  11. Redefining of a Picarto JS function emoticonize
  12. */
  13. window.$.fn.emoticonize = function (options) {
  14. var opts = $.extend({
  15. }, $.fn.emoticonize.defaults, options);
  16. var escapeCharacters = [
  17. ')', '(', '*', '[', ']', '{', '}', '|', '^', '<', '>', '\\', '?', '+', '=', '.'
  18. ];
  19. var threeCharacterEmoticons = [
  20. // really weird bug if you have :{ and then have :{) in the same container anywhere *after* :{ then :{ doesn't get matched, e.g. :] :{ :) :{) :) :-) will match everything except :{
  21. // But if you take out the :{) or even just move :{ to the right of :{) then everything works fine. This has something to do with the preMatch string below I think, because
  22. // it'll work again if you set preMatch equal to '()'
  23. // So for now, we'll just remove :{) from the emoticons, because who actually uses this mustache man anyway?
  24. // ":{)", ':-)', ':o)', ':c)', ':^)', ':-D', ':-(', ':-9', ';-)', ':-P', ':-p', ':-Þ', ':-b', ':-O', ':-/', ':-X', ':-#', ':\'(', 'B-)', '8-)', ';*(', ':-*', ':-\\', '?-)', // <== This is my own invention, it's a smiling pirate (with an eye-patch)!
  25. // and the twoCharacterEmoticons from below, but with a space inserted
  26. ': )', ': ]', '= ]', '= )', '8 )', ': }', ': D', '8 D', 'X D', 'x D', '= D', ': (', ': [', ': {', '= (', '; )', '; ]', '; D', ': P', ': p', '= P', '= p', ': b', ': Þ', ': O', '8 O', ': /', '= /', ': S', ': #', ': X', 'B )', ': |', ': \\', '= \\', ': *', ': &gt;', ': &lt;' //, "* )"
  27. ];
  28. var twoCharacterEmoticons = [ // separate these out so that we can add a letter-spacing between the characters for better proportions
  29. ':)', ':]', '=]', '=)', '8)', ':}', ':D', ':(', ':[', ':{', '=(', ';)', ';]', ';D', ':P', ':p', '=P', '=p', ':b', ':Þ', ':O', ':/', '=/', ':S', ':#', ':X', 'B)', ':|', ':\\', '=\\', ':*', ':&gt;', ':&lt;' //, "*)"
  30. ];
  31. var specialRegex = new RegExp('(\\' + escapeCharacters.join('|\\') + ')', 'g');
  32. // One of these characters must be present before the matched emoticon, or the matched emoticon must be the first character in the container HTML
  33. // This is to ensure that the characters in the middle of HTML properties or URLs are not matched as emoticons
  34. // Below matches ^ (first character in container HTML), \s (whitespace like space or tab), or \0 (NULL character)
  35. // (<\\S+.*>) matches <\\S+.*> (matches an HTML tag like <span> or <div>), but haven't quite gotten it working yet, need to push this fix now
  36. var preMatch = '(^|[\\s\\0])';
  37. for (var i = threeCharacterEmoticons.length - 1; i >= 0; --i) {
  38. threeCharacterEmoticons[i] = threeCharacterEmoticons[i].replace(specialRegex, '\\$1');
  39. threeCharacterEmoticons[i] = new RegExp(preMatch + '(' + threeCharacterEmoticons[i] + ')', 'g');
  40. }
  41. for (var i = twoCharacterEmoticons.length - 1; i >= 0; --i) {
  42. twoCharacterEmoticons[i] = twoCharacterEmoticons[i].replace(specialRegex, '\\$1');
  43. twoCharacterEmoticons[i] = new RegExp(preMatch + '(' + twoCharacterEmoticons[i] + ')', 'g');
  44. }
  45. /*for ( var emoticon in specialEmoticons ){
  46. specialEmoticons[emoticon].regexp = emoticon.replace(specialRegex,'\\$1');
  47. specialEmoticons[emoticon].regexp = new RegExp( preMatch+'(' + specialEmoticons[emoticon].regexp + ')', 'g' );
  48. }*/
  49.  
  50. var exclude = 'span.css-emoticon';
  51. if (opts.exclude) {
  52. exclude += ',' + opts.exclude;
  53. }
  54. var excludeArray = exclude.split(',')
  55. return this.not(exclude).each(function () {
  56. var container = $(this);
  57. var cssClass = 'css-emoticon'
  58. if (opts.animate) {
  59. cssClass += ' un-transformed-emoticon animated-emoticon';
  60. }
  61. var time_var = new Date().getTime();
  62. var content = container.html();
  63. /* NORMAL SMILIES */
  64. if (content.match(/:sad:/g)) {
  65. content = (content.replace(/:sad:/g, '<img title=\'...\' class=\'emoti animated rubberBand\' src=\'../images/chat/emoticons/sad.png\'>'));
  66. }
  67. if (content.match(/:angry:/g)) {
  68. content = (content.replace(/:angry:/g, '<img title=\'...\' class=\'emoti animated jello\' src=\'../images/chat/emoticons/angry.png\'>'));
  69. }
  70. if (content.match(/:condescending:/g)) {
  71. content = (content.replace(/:condescending:/g, '<img title=\'...\' class=\'emoti animated swing\' src=\'../images/chat/emoticons/condescending.png\'>'));
  72. }
  73. if (content.match(/:confused:/g)) {
  74. content = (content.replace(/:confused:/g, '<img title=\'...\' class=\'emoti animated shake\' src=\'../images/chat/emoticons/confused.png\'>'));
  75. }
  76. if (content.match(/:excited:/g)) {
  77. content = (content.replace(/:excited:/g, '<img title=\'...\' class=\'emoti animated shake\' src=\'../images/chat/emoticons/excited.png\'>'));
  78. }
  79. if (content.match(/:grossedout:/g)) {
  80. content = (content.replace(/:grossedout:/g, '<img title=\'...\' class=\'emoti animated wobble\' src=\'../images/chat/emoticons/grossedout.png\'>'));
  81. }
  82. if (content.match(/:laugh:/g)) {
  83. content = (content.replace(/:laugh:/g, '<img title=\'...\' class=\'emoti animated bounce\' src=\'../images/chat/emoticons/laugh.png\'>'));
  84. }
  85. if (content.match(/:ohmy:/g)) {
  86. content = (content.replace(/:ohmy:/g, '<img title=\'...\' class=\'emoti animated shake\' src=\'../images/chat/emoticons/ohmy.png\'>'));
  87. }
  88. if (content.match(/:pouty:/g)) {
  89. content = (content.replace(/:pouty:/g, '<img title=\'...\' class=\'emoti animated jello\' src=\'../images/chat/emoticons/pouty.png\'>'));
  90. }
  91. if (content.match(/:sad:/g)) {
  92. content = (content.replace(/:sad:/g, '<img title=\'...\' class=\'emoti animated swing\' src=\'../images/chat/emoticons/sad.png\'>'));
  93. }
  94. if (content.match(/:shock:/g)) {
  95. content = (content.replace(/:shock:/g, '<img title=\'...\' class=\'emoti animated tada\' src=\'../images/chat/emoticons/shock.png\'>'));
  96. }
  97. if (content.match(/:sleepy:/g)) {
  98. content = (content.replace(/:sleepy:/g, '<img title=\'...\' class=\'emoti animated pulse\' src=\'../images/chat/emoticons/sleepy.png\'>'));
  99. }
  100. if (content.match(/:snicker:/g)) {
  101. content = (content.replace(/:snicker:/g, '<img title=\'...\' class=\'emoti animated bounce\' src=\'../images/chat/emoticons/snicker.png\'>'));
  102. }
  103. if (content.match(/:uneasy:/g)) {
  104. content = (content.replace(/:uneasy:/g, '<img title=\'...\' class=\'emoti animated jello\' src=\'../images/chat/emoticons/uneasy.png\'>'));
  105. }
  106. if (content.match(/:unimpressed:/g)) {
  107. content = (content.replace(/:unimpressed:/g, '<img title=\'...\' class=\'emoti animated shake\' src=\'../images/chat/emoticons/unimpressed.png\'>'));
  108. }
  109. if (content.match(/:whiny:/g)) {
  110. content = (content.replace(/:whiny:/g, '<img title=\'...\' class=\'emoti animated rubberBand\' src=\'../images/chat/emoticons/whiny.png\'>'));
  111. }
  112. if (content.match(/:kippi:/g)) {
  113. content = (content.replace(/:kippi:/g, '<img title=\'...\' class=\'emoti animated tada\' src=\'../images/chat/emoticons/kippi.png\'>'));
  114. }
  115. if (content.match(/:kippi2:/g)) {
  116. content = (content.replace(/:kippi2:/g, '<img title=\'...\' class=\'emoti animated tada\' src=\'../images/chat/emoticons/kippi2.png\'>'));
  117. }
  118. if (content.match(/:kippi3:/g)) {
  119. content = (content.replace(/:kippi3:/g, '<img title=\'...\' class=\'emoti animated tada\' src=\'../images/chat/emoticons/kippi3.png\'>'));
  120. }
  121. //MEME
  122. if(content.match(/:meme1:/g)){
  123. content = (content.replace(/\:meme1\:/g,"<img title='Forever alone ;_;' class='memeEmoti animated jello' src='../images/chat/emoticons/meme/alone.png'>"));
  124. }
  125. if(content.match(/:meme2:/g)){
  126. content = (content.replace(/\:meme2\:/g,"<img title='Jackie why?!' class='memeEmoti animated shake' src='../images/chat/emoticons/meme/jackie.png'>"));
  127. }
  128. if(content.match(/:meme3:/g)){
  129. content = (content.replace(/\:meme3\:/g,"<img title='NO WAY!' class='memeEmoti animated flash' src='../images/chat/emoticons/meme/whaaat.jpg'>"));
  130. }
  131. if(content.match(/:meme4:/g)){
  132. content = (content.replace(/:meme4:/g,"<img title='DSFGHG ERUJW TGDF J' class='memeEmoti animated swing' src='../images/chat/emoticons/meme/arms.gif'>"));
  133. }
  134. if(content.match(/:meme5:/g)){
  135. content = (content.replace(/:meme5:/g,"<img title='FU DA BI' class='memeEmoti animated rubberBand' src='../images/chat/emoticons/meme/fubu.png'>"));
  136. }
  137. /* HEART */
  138.  
  139. if (content.match(/&lt;3/g)) {
  140. content = (content.replace(/&lt;3/g, '<span class=\'animated rubberBand heart\'></span>'));
  141. }
  142. container.html(content);
  143. // fix emoticons that got matched more then once (where one emoticon is a subset of another emoticon), and thus got nested spans
  144. $.each(excludeArray, function (index, item) {
  145. container.find($.trim(item) + ' span.css-emoticon').each(function () {
  146. $(this).replaceWith($(this).text());
  147. });
  148. });
  149. if (opts.animate) {
  150. setTimeout(function () {
  151. $('.un-transformed-emoticon').removeClass('un-transformed-emoticon');
  152. }, opts.delay);
  153. }
  154. });
  155. }