From 63a8d60ee12283a0a6ab0aa4f21f06e041f2d300 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Fri, 11 Dec 2015 11:13:38 +0200 Subject: [PATCH] Fixed edit emotes --- js/main.js | 83 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/js/main.js b/js/main.js index 9df22184..af8f3ed6 100644 --- a/js/main.js +++ b/js/main.js @@ -375,37 +375,46 @@ EmoteModule.prototype.injectEmote = function(node) { if(!node.parentElement) return; var parent = node.parentElement; + if(parent.tagName != "SPAN") return; - if(!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) return; + + var edited = false; + + if($(parent.parentElement).hasClass("edited")) { + parent = parent.parentElement.parentElement.firstChild; //:D + edited = true; + } + + //if(!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) return; - var parentInnerHTML = parent.innerHTML; - var words = parentInnerHTML.split(/\s+/g); + function inject() { + if(!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) { return; } - if(!words) return; + var parentInnerHTML = parent.innerHTML; + var words = parentInnerHTML.split(/\s+/g); - words.some(function(word) { + if(!words) return; - if(word.slice(0, 4) == "[!s]" ) { + words.some(function(word) { - parentInnerHTML = parentInnerHTML.replace("[!s]", ""); + if(word.slice(0, 4) == "[!s]" ) { - var markup = $(parent).parent(); + parentInnerHTML = parentInnerHTML.replace("[!s]", ""); + var markup = $(parent).parent(); + var reactId = markup.attr("data-reactid"); + + if(spoilered.indexOf(reactId) > -1) { + return; + } - var reactId = markup.attr("data-reactid"); + markup.addClass("spoiler"); + markup.on("click", function() { + $(this).removeClass("spoiler"); + spoilered.push($(this).attr("data-reactid")); + }); - if(spoilered.indexOf(reactId) > -1) { return; } - - markup.addClass("spoiler"); - - markup.on("click", function() { - $(this).removeClass("spoiler"); - spoilered.push($(this).attr("data-reactid")); - }); - - return; - } if(word.length < 4) { return; @@ -414,24 +423,24 @@ EmoteModule.prototype.injectEmote = function(node) { if($.inArray(word, bemotes) != -1) return; if (emotesTwitch.emotes.hasOwnProperty(word)) { - var len = Math.round(word.length / 4); - parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + ' ); - return; + var len = Math.round(word.length / 4); + parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + ' ); + return; } if (typeof emotesFfz !== 'undefined' && settingsCookie["bda-es-1"]) { if (emotesFfz.hasOwnProperty(word)) { - var len = Math.round(word.length / 4); - parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); - return; - } + var len = Math.round(word.length / 4); + parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); + return; + } } if (typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) { if (emotesBTTV.hasOwnProperty(word)) { - var len = Math.round(word.length / 4); - parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); - return; + var len = Math.round(word.length / 4); + parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); + return; } } @@ -444,9 +453,9 @@ EmoteModule.prototype.injectEmote = function(node) { } if (subEmotesTwitch.hasOwnProperty(word)) { - var len = Math.round(word.length / 4); - parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); - return; + var len = Math.round(word.length / 4); + parentInnerHTML = parentInnerHTML.replace(word, '' + word.substr(0, len) + '); + return; } }); @@ -459,6 +468,14 @@ EmoteModule.prototype.injectEmote = function(node) { //Scrollfix var scrollPane = $(".scroller.messages").first(); scrollPane.scrollTop(scrollPane.scrollTop() + (newHeight - oldHeight)); + } + + if(edited) { + setTimeout(inject, 250); + } else { + inject(); + } + }; EmoteModule.prototype.autoCapitalize = function() {