From b6d7a92b32f7ef7f507e0e456fbf14878b1eb740 Mon Sep 17 00:00:00 2001 From: RCTrapdoor Date: Tue, 8 Oct 2013 10:49:33 +0200 Subject: [PATCH] Padding left zero on seconds <10, (5:09 instead of 5:9) as well as thousands separator on viewCount I'm not entirely sure if the thousands separator will work like that, but there's only one way to find out. --- modules/youtube/youtube.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/youtube/youtube.js b/modules/youtube/youtube.js index 4c619bb..32fe0d7 100644 --- a/modules/youtube/youtube.js +++ b/modules/youtube/youtube.js @@ -28,6 +28,7 @@ var youtube = function(dbot) { seconds = v['media$group']['yt$duration'].seconds, minutes = Math.floor(seconds / 60), seconds = seconds - minutes * 60; + if (seconds < 10) seconds = '0'+seconds; if(!_.has(v, 'yt$rating')) { v['yt$rating'] = { @@ -42,7 +43,7 @@ var youtube = function(dbot) { var link = v.link[0].href.match(this.LinkRegex)[2]; event.reply(dbot.t('yt_video', { 'title': v.title['$t'], - 'plays': v['yt$statistics'].viewCount, + 'plays': v['yt$statistics'].viewCount.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 "), 'author': v.author[0].name['$t'], 'likes': v['yt$rating'].numLikes, 'dislikes': v['yt$rating'].numDislikes, @@ -69,6 +70,7 @@ var youtube = function(dbot) { seconds = v['media$group']['yt$duration'].seconds, minutes = Math.floor(seconds / 60), seconds = seconds - minutes * 60; + if (seconds < 10) seconds = '0'+seconds; if(!_.has(v, 'yt$rating')) { v['yt$rating'] = { @@ -82,7 +84,7 @@ var youtube = function(dbot) { callback(dbot.t('yt_video', { 'title': v.title['$t'], - 'plays': v['yt$statistics'].viewCount, + 'plays': v['yt$statistics'].viewCount.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 "), 'author': v.author[0].name['$t'], 'likes': v['yt$rating'].numLikes, 'dislikes': v['yt$rating'].numDislikes,