var FFZ = window.FrankerFaceZ, constants = require('../constants'), utils = require('../utils'), SENDER_REGEX = /(\sdata-sender="[^"]*"(?=>))/, HOP = Object.prototype.hasOwnProperty; // -------------------- // Initialization // -------------------- FFZ.prototype.find_bttv = function(increment, delay) { this.has_bttv = this.has_bttv_6 = this.has_bttv_7 = false; if ( window.BetterTTV && BetterTTV.version && BetterTTV.version.indexOf('7.') === 0 ) return this.setup_bttv_7(delay||0); if ( window.BTTVLOADED ) return this.setup_bttv(delay||0); if ( delay >= 60000 ) this.log("BetterTTV was not detected after 60 seconds."); else setTimeout(this.find_bttv.bind(this, increment, (delay||0) + increment), increment); } FFZ.prototype.setup_bttv_7 = function(delay) { this.log("BetterTTV v7 was detected after " + delay + "ms. Hooking."); this.has_bttv = 7; this.has_bttv_6 = false; this.has_bttv_7 = true; var settings = BetterTTV.settings, cl = document.body.classList; // Disable FFZ Dark if it's enabled. cl.remove("ffz-dark"); if ( this._dark_style ) { this._dark_style.parentElement.removeChild(this._dark_style); this._dark_style = undefined; } // Disable other styling. if ( this._layout_style ) { this._layout_style.parentElement.removeChild(this._layout_style); this._layout_style = undefined; } if ( this._chat_style ) { utils.update_css(this._chat_style, 'chat_font_size', ''); utils.update_css(this._chat_style, 'chat_ts_font_size', ''); } this.toggle_style('chat-padding'); this.toggle_style('chat-background'); this.toggle_style('chat-separator'); this.toggle_style('chat-separator-3d'); this.toggle_style('chat-separator-3d-inset'); this.toggle_style('chat-separator-wide'); this.toggle_style('chat-colors-gray'); /*this.toggle_style('badges-rounded'); this.toggle_style('badges-circular'); this.toggle_style('badges-blank'); this.toggle_style('badges-circular-small'); this.toggle_style('badges-transparent');*/ this.toggle_style('badges-sub-notice'); this.toggle_style('badges-sub-notice-on'); //cl.remove('ffz-transparent-badges'); cl.remove("ffz-sidebar-swap"); cl.remove("ffz-portrait"); cl.remove("ffz-minimal-channel-title"); cl.remove("ffz-flip-dashboard"); cl.remove('ffz-minimal-channel-bar'); cl.remove('ffz-channel-bar-bottom'); cl.remove('ffz-channel-title-top'); cl.remove('ffz-sidebar-minimize'); cl.remove('ffz-alias-italics'); // Update the layout service. var Layout = utils.ember_lookup('service:layout'); if ( Layout ) { Layout.set('ffzMinimizeNavigation', false); Layout.set('rawPortraitMode', 0); } // Remove Following Count if ( this.settings.following_count ) { this._schedule_following_count(); this._draw_following_count(); this._draw_following_channels(); } /* Update the chat input to not use FFZ's input handling. if ( this._inputv ) { var t = this._inputv.$("textarea"); t.off("keyup"); t.off("keydown"); t.off("keypress"); t.on("keyup", this._inputv._onKeyUp.bind(this._inputv)); t.on("keydown", this._inputv._onKeyDown.bind(this._inputv)); }//*/ // Hook into BTTV's dark mode. cl.add('ffz-bttv'); cl.toggle('ffz-bttv-dark', settings.get('darkenedMode')); settings.on('changed.darkenedMode', function(val) { cl.toggle('ffz-bttv-dark', val); }); this.update_ui_link(); this._roomv && this._roomv.ffzUpdateRecent(); this.api_trigger('bttv-initialized', 7); } FFZ.prototype.setup_bttv = function(delay) { this.log("BetterTTV was detected after " + delay + "ms. Hooking."); this.has_bttv = true; this.has_bttv_6 = true; this.has_bttv_7 = false; // Disable Dark if it's enabled. document.body.classList.remove("ffz-dark"); if ( this._dark_style ) { this._dark_style.parentElement.removeChild(this._dark_style); this._dark_style = undefined; } if ( this._layout_style ) { this._layout_style.parentElement.removeChild(this._layout_style); this._layout_style = undefined; } if ( this._chat_style ) { utils.update_css(this._chat_style, 'chat_font_size', ''); utils.update_css(this._chat_style, 'chat_ts_font_size', ''); } // Remove Sub Count and the Chart if ( this.is_dashboard ) { this._update_subscribers(); this._remove_dash_chart(); } document.body.classList.add('ffz-bttv'); var last_dark = BetterTTV.settings.get('darkenedMode'); document.body.classList.toggle('ffz-bttv-dark', last_dark); setInterval(function() { var new_dark = BetterTTV.settings.get('darkenedMode'); if ( new_dark !== last_dark ) { document.body.classList.toggle('ffz-bttv-dark', new_dark); last_dark = new_dark; } }, 500); // Disable Chat Tabs if ( this._chatv ) { if ( this.settings.group_tabs ) this._chatv.ffzDisableTabs(); this._chatv.ffzTeardownMenu(); this._chatv.ffzUnloadHost(); } if ( this._roomv ) { // Disable Chat Pause this._roomv.ffzDisableFreeze(); this._roomv.ffzRemoveKeyHook(); // And hide the status if ( this.settings.room_status ) this._roomv.ffzUpdateStatus(); } this.disconnect_extra_chat(); // Disable style blocks. this.toggle_style('chat-padding'); this.toggle_style('chat-background'); this.toggle_style('chat-separator'); this.toggle_style('chat-separator-3d'); this.toggle_style('chat-separator-3d-inset'); this.toggle_style('chat-separator-wide'); this.toggle_style('chat-colors-gray'); this.toggle_style('badges-rounded'); this.toggle_style('badges-circular'); this.toggle_style('badges-blank'); this.toggle_style('badges-circular-small'); this.toggle_style('badges-transparent'); this.toggle_style('badges-sub-notice'); this.toggle_style('badges-sub-notice-on'); // Disable other features too. var cl = document.body.classList; cl.remove('ffz-transparent-badges'); cl.remove("ffz-sidebar-swap"); cl.remove("ffz-portrait"); cl.remove("ffz-minimal-channel-title"); cl.remove("ffz-flip-dashboard"); cl.remove('ffz-minimal-channel-bar'); cl.remove('ffz-channel-bar-bottom'); cl.remove('ffz-channel-title-top'); cl.remove('ffz-sidebar-minimize'); cl.remove('ffz-alias-italics'); // Update the layout service. var Layout = utils.ember_lookup('service:layout'); if ( Layout ) { Layout.set('ffzMinimizeNavigation', false); Layout.set('rawPortraitMode', 0); } // Remove Following Count if ( this.settings.following_count ) { this._schedule_following_count(); this._draw_following_count(); this._draw_following_channels(); } // Send Message Behavior var f = this, BC = BetterTTV.chat, original_send = BC.helpers.sendMessage; BC.helpers.sendMessage = function(message) { var cmd = message.split(' ', 1)[0].toLowerCase(); if ( cmd === '/ffz' ) f.run_ffz_command(message.substr(5), BC.store.currentRoom); else return original_send(message); } // Ugly Hack for Current Room, as this is stripped out before we get to // the actual privmsg renderer. var original_handler = BC.handlers.onPrivmsg, received_room; BC.handlers.onPrivmsg = function(room, data) { received_room = room; var output = original_handler(room, data); received_room = null; return output; } // Message Display Behavior var original_privmsg = BC.templates.privmsg; BC.templates.privmsg = function(data, opts) { try { opts = opts || {}; // Handle badges. data.room = data.room || received_room; f.bttv_badges(data); // API Support f.api_trigger('bttv-room-message', data, opts); // Now, do everything else manually because things are hard-coded. return '