diff --git a/index.html b/index.html index e56cb12..0273904 100644 --- a/index.html +++ b/index.html @@ -162,7 +162,7 @@ {{ part.text }} - {{ part.text }} +
diff --git a/js/plugins.js b/js/plugins.js index af04f2b..a151128 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -55,31 +55,46 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) */ var contentForMessage = function(message) { - var content = []; + message.metadata = []; for (var i = 0; i < plugins.length; i++) { var nsfw = false; var visible = true; - if (message.match(nsfwRegexp)) { + if (message.text.match(nsfwRegexp)) { var nsfw = true; var visible = false; } - var pluginContent = plugins[i].contentForMessage(message); + var pluginContent = plugins[i].contentForMessage(message.text); if (pluginContent) { var pluginContent = {'visible': visible, 'content': $sce.trustAsHtml(pluginContent), 'nsfw': nsfw, 'name': plugins[i].name } - content.push(pluginContent); + message.metadata.push(pluginContent); + if (plugins[i].exclusive) { break; } } } - return content; + + /* Replace all URLs with hyperlinks */ + + var urlRegexp = RegExp(/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/g); + for(k in message.content) { + var text = message.content[k].text; + var url = text.match(urlRegexp); + for(i in url) { + var u = url[i]; + text = text.replace(u, '' + u + ''); + } + message.content[k].text = $sce.trustAsHtml(text); + } + + return message; } return { @@ -124,16 +139,6 @@ plugins.factory('userPlugins', function() { }); youtubePlugin.name = 'youtube video'; - var urlPlugin = new Plugin(function(message) { - var url = message.match(urlRegexp); - if (url) { - return '' + url[0] + ''; - } - return null; - - }); - urlPlugin.name = 'url'; - var imagePlugin = new Plugin(function(message) { var url = message.match(urlRegexp); @@ -149,6 +154,6 @@ plugins.factory('userPlugins', function() { imagePlugin.name = 'image'; return { - plugins: [youtubePlugin, urlPlugin, imagePlugin] + plugins: [youtubePlugin, imagePlugin] } }); diff --git a/js/websockets.js b/js/websockets.js index 9715ed2..1ad4c59 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -191,7 +191,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi // Only react to line if its displayed if(message.displayed) { var buffer = models.getBuffer(message.buffer); - message.metadata = plugins.PluginManager.contentForMessage(message.text); + message = plugins.PluginManager.contentForMessage(message); buffer.addLine(message); if (buffer.active) {