diff options
Diffstat (limited to 'data/lib/comments.js')
-rw-r--r-- | data/lib/comments.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/data/lib/comments.js b/data/lib/comments.js new file mode 100644 index 0000000..3b35517 --- /dev/null +++ b/data/lib/comments.js @@ -0,0 +1,53 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; + +function Comment(comment) { + var nameSpan = comment.querySelector(".bz_comment_user a.email"); + var timeSpan = comment.getElementsByClassName("bz_comment_time")[0]; + + this.author = parseMailto(nameSpan).trim(); + this.element = comment; + this.date = parseBZCommentDate(timeSpan.textContent.trim()); + this.timeSpan = timeSpan; +} + +Comment.prototype.getText = function getText() { + return this.element.getElementsByTagName("pre")[0].textContent.trim(); +} + +function CommentList(doc) { + var commentElems = document.getElementById("comments"). + getElementsByClassName("bz_comment"); + var comments = {}; + Array.forEach(commentElems, function(item) { + var com = new Comment(item); + if (com.element) { + comments[ISODateString(com.date)] = com; + } + }); + this.comments = comments; +} + +/** + * Set background color of all comments made by reporter in ReporterColor color + * + */ +CommentList.prototype.colorComments = function colorComments() { + var reporter = getReporter(); + var com = null; + for (var idx in this.comments) { + com = this.comments[idx]; + if (com.author === reporter) { + com.element.style.backgroundColor = ReporterColor.toString(); + } + } +} + +CommentList.prototype.getAllCommentsText = function getAllCommentsText() { + var outStr = ""; + for (var idx in this.comments) { + outStr += this.comments[idx].getText() + "\n"; + } + return outStr; +} |