From 39b6d7a179aa21b347acc0277da7270b93997ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 14 Jul 2014 22:49:26 +0100 Subject: [PATCH 1/3] Fix URL regex Old one doesn't match umlauts and other unicode stuff New one is a lot more general and similar to what angular uses --- js/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/plugins.js b/js/plugins.js index e251a5d..0de3850 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -111,7 +111,7 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) { */ plugins.factory('userPlugins', function() { - var urlRegexp = RegExp(/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/); + var urlRegexp = RegExp(/(ftp|https?):\/\/\S*[^\s.;,(){}<>]/) /* * Spotify Embedded Player From 885b47eaaf1888dbe4d2c3b9c0c22c283d104aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 14 Jul 2014 22:50:08 +0100 Subject: [PATCH 2/3] Add yr.no plugin --- js/plugins.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index 0de3850..db21075 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -111,7 +111,7 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) { */ plugins.factory('userPlugins', function() { - var urlRegexp = RegExp(/(ftp|https?):\/\/\S*[^\s.;,(){}<>]/) + var urlRegexp = RegExp(/(ftp|https?):\/\/\S*[^\s.;,(){}<>]/); /* * Spotify Embedded Player @@ -287,8 +287,27 @@ plugins.factory('userPlugins', function() { }); asciinemaPlugin.name = "ascii cast"; + var yrPlugin = new Plugin(function(message) { + var match = message.match(urlRegexp); + + if (match) { + var url = match[0]; + var regexp = /^https?:\/\/(?:www\.)?yr\.no\/(place|stad|sted|sadji)\/([^\s.;,(){}<>\/]+)\/([^\s.;,(){}<>\/]+)\/([^\s.;,(){}<>\/]+)/; + match = url.match(regexp); + if (match) { + var language = match[1]; + var country = match[2]; + var province = match[3]; + var city = match[4]; + url = "http://www.yr.no/" + language + "/" + country + "/" + province + "/" + city + "/avansert_meteogram.png"; + return "Meteogram for " + city + ""; + } + } + }); + yrPlugin.name = "meteogram"; + return { - plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin] + plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin] }; From 8e1e87141147d601d6c7d0c367eef7d9fbe2f2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 14 Jul 2014 23:17:22 +0100 Subject: [PATCH 3/3] Fix matching (#segments) --- js/plugins.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index db21075..eba813d 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -292,14 +292,13 @@ plugins.factory('userPlugins', function() { if (match) { var url = match[0]; - var regexp = /^https?:\/\/(?:www\.)?yr\.no\/(place|stad|sted|sadji)\/([^\s.;,(){}<>\/]+)\/([^\s.;,(){}<>\/]+)\/([^\s.;,(){}<>\/]+)/; + var regexp = /^https?:\/\/(?:www\.)?yr\.no\/(place|stad|sted|sadji|paikka)\/(([^\s.;,(){}<>\/]+\/){3,})/; match = url.match(regexp); if (match) { var language = match[1]; - var country = match[2]; - var province = match[3]; - var city = match[4]; - url = "http://www.yr.no/" + language + "/" + country + "/" + province + "/" + city + "/avansert_meteogram.png"; + var location = match[2]; + var city = match[match.length - 1].slice(0, -1); + url = "http://www.yr.no/" + language + "/" + location + "avansert_meteogram.png"; return "Meteogram for " + city + ""; } }