From 5b708295b520e162736d996207f82bcc65b3ef28 Mon Sep 17 00:00:00 2001 From: Zac Colley Date: Thu, 13 Nov 2014 22:37:02 +0000 Subject: [PATCH 1/4] Styled soundcloud embed --- app/css/app.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/css/app.css b/app/css/app.css index a0d8f423..3167200c 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1308,6 +1308,9 @@ div.im_message_video_thumb { .im_message_vine_embed { padding-bottom: 100%; } +.im_message_soundcloud_embed { + padding-bottom: 56.25%; /* 16/9 ratio */ +} .im_message_media_embed iframe, .im_message_media_embed webview { position: absolute; From 4c9380e176efe355b446fb5940db8b2d9a80dff1 Mon Sep 17 00:00:00 2001 From: Zac Colley Date: Thu, 13 Nov 2014 22:38:14 +0000 Subject: [PATCH 2/4] Regex and matching for Soundcloud track URLS --- app/js/services.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/js/services.js b/app/js/services.js index 628417b0..f1a87b7b 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -3121,6 +3121,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var twitterRegex = /https?:\/\/twitter\.com\/.+?\/status\/\d+/i; var facebookRegex = /https?:\/\/(?:www\.)?facebook\.com\/.+?\/posts\/\d+/i; var gplusRegex = /https?:\/\/plus\.google\.com\/\d+\/posts\/[a-zA-Z0-9\-\_]+/i; + var soundcloudRegex = /https?:\/\/(soundcloud.com|snd.sc)\/[a-zA-Z0-9\-\_]+\/[a-zA-Z0-9\-\_]+/i; return { wrapRichText: wrapRichText, @@ -3266,6 +3267,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) else if (embedUrlMatches = text.match(vineRegex)) { return ['vine', embedUrlMatches[1]]; } + else if (embedUrlMatches = text.match(soundcloudRegex)) { + return ['soundcloud', embedUrlMatches[0]]; + } if (!Config.Modes.chrome_packed) { // Need external JS if (embedUrlMatches = text.match(twitterRegex)) { From 1f159bc8c9f710a5ca8376174b49d51fa1d4f536 Mon Sep 17 00:00:00 2001 From: Zac Colley Date: Thu, 13 Nov 2014 22:38:37 +0000 Subject: [PATCH 3/4] Embed code for Soundcloud --- app/js/directives.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/js/directives.js b/app/js/directives.js index 357b9f59..0f6f67a0 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -211,6 +211,13 @@ angular.module('myApp.directives', ['myApp.filters']) 'src="//vine.co/v/' + vineID + '/embed/simple">'; break; + case 'soundcloud': + var soundcloudUrl = embedData[1]; + html = '
<' + embedTag + ' type="text/html" frameborder="0" ' + + 'src="https://w.soundcloud.com/player/?url=' + soundcloudUrl + + '&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&visual=true">
'; + break; + case 'twitter': html = '
'; From cab5631cb932328f7d0414f866699af351d24b83 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 14 Nov 2014 13:32:21 +0300 Subject: [PATCH 4/4] Improved Soundcloud regex, added escaping --- app/js/directives.js | 4 ++-- app/js/services.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/js/directives.js b/app/js/directives.js index 0f6f67a0..b0a545af 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -214,8 +214,8 @@ angular.module('myApp.directives', ['myApp.filters']) case 'soundcloud': var soundcloudUrl = embedData[1]; html = '
<' + embedTag + ' type="text/html" frameborder="0" ' + - 'src="https://w.soundcloud.com/player/?url=' + soundcloudUrl + - '&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&visual=true">
'; + 'src="https://w.soundcloud.com/player/?url=' + encodeEntities(encodeURIComponent(soundcloudUrl)) + + '&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&visual=true">'; break; case 'twitter': diff --git a/app/js/services.js b/app/js/services.js index f1a87b7b..3b96644c 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -3114,14 +3114,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; var regExp = new RegExp('((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>"\']))|(\\n)|(' + emojiUtf.join('|') + ')|(^|\\s)(#[' + regexAlphaNumericChars + ']{3,20})', 'i'); - var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; + var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|\.be|be\.com|\.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; var vimeoRegex = /(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)/; var instagramRegex = /https?:\/\/(?:instagr\.am\/p\/|instagram\.com\/p\/)([a-zA-Z0-9\-\_]+)/i; var vineRegex = /https?:\/\/vine\.co\/v\/([a-zA-Z0-9\-\_]+)/i; var twitterRegex = /https?:\/\/twitter\.com\/.+?\/status\/\d+/i; var facebookRegex = /https?:\/\/(?:www\.)?facebook\.com\/.+?\/posts\/\d+/i; var gplusRegex = /https?:\/\/plus\.google\.com\/\d+\/posts\/[a-zA-Z0-9\-\_]+/i; - var soundcloudRegex = /https?:\/\/(soundcloud.com|snd.sc)\/[a-zA-Z0-9\-\_]+\/[a-zA-Z0-9\-\_]+/i; + var soundcloudRegex = /https?:\/\/(?:soundcloud\.com|snd\.sc)\/([a-zA-Z0-9%\-\_]+)\/([a-zA-Z0-9%\-\_]+)/i; return { wrapRichText: wrapRichText, @@ -3268,7 +3268,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return ['vine', embedUrlMatches[1]]; } else if (embedUrlMatches = text.match(soundcloudRegex)) { - return ['soundcloud', embedUrlMatches[0]]; + if (embedUrlMatches[1] != 'explore') { + return ['soundcloud', embedUrlMatches[0]]; + } } if (!Config.Modes.chrome_packed) { // Need external JS