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] 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] };