Comma seperate comment scores

This commit is contained in:
Omar Roth 2018-10-20 13:52:06 -05:00
parent 3c634d9f66
commit 3ee7201f5d
3 changed files with 10 additions and 10 deletions

View File

@ -28,13 +28,6 @@ function swap_comments(source) {
} }
} }
function commaSeparateNumber(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2");
}
return val;
}
String.prototype.supplant = function(o) { String.prototype.supplant = function(o) {
return this.replace(/{([^{}]*)}/g, function(a, b) { return this.replace(/{([^{}]*)}/g, function(a, b) {
var r = o[b]; var r = o[b];

View File

@ -115,7 +115,7 @@ def template_youtube_comments(comments)
<p style="white-space:pre-wrap">#{child["contentHtml"]}</p> <p style="white-space:pre-wrap">#{child["contentHtml"]}</p>
#{recode_date(Time.epoch(child["published"].as_i64))} ago #{recode_date(Time.epoch(child["published"].as_i64))} ago
| |
<i class="icon ion-ios-thumbs-up"></i> #{child["likeCount"]} <i class="icon ion-ios-thumbs-up"></i> #{number_with_separator(child["likeCount"])}
</p> </p>
#{replies_html} #{replies_html}
</div> </div>
@ -158,7 +158,7 @@ def template_reddit_comments(root)
<p> <p>
<a href="javascript:void(0)" onclick="toggle_parent(this)">[ - ]</a> <a href="javascript:void(0)" onclick="toggle_parent(this)">[ - ]</a>
<b><a href="https://www.reddit.com/user/#{author}">#{author}</a></b> <b><a href="https://www.reddit.com/user/#{author}">#{author}</a></b>
#{score} points #{number_with_separator(score)} points
#{recode_date(child.created_utc)} ago #{recode_date(child.created_utc)} ago
</p> </p>
<div> <div>

View File

@ -152,6 +152,13 @@
</div> </div>
<script> <script>
function number_with_separator(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2");
}
return val;
}
subscribe_button = document.getElementById("subscribe"); subscribe_button = document.getElementById("subscribe");
if (subscribe_button.getAttribute('onclick')) { if (subscribe_button.getAttribute('onclick')) {
subscribe_button["href"] = "javascript:void(0);"; subscribe_button["href"] = "javascript:void(0);";
@ -345,7 +352,7 @@ function get_youtube_comments() {
<div>{contentHtml}</div> \ <div>{contentHtml}</div> \
<hr>'.supplant({ <hr>'.supplant({
contentHtml: xhr.response.contentHtml, contentHtml: xhr.response.contentHtml,
commentCount: commaSeparateNumber(xhr.response.commentCount) commentCount: number_with_separator(xhr.response.commentCount)
}); });
} else { } else {
comments.innerHTML = ""; comments.innerHTML = "";