diff --git a/extension/data/modules/betterbuttons.js b/extension/data/modules/betterbuttons.js index fc38351..f59856d 100644 --- a/extension/data/modules/betterbuttons.js +++ b/extension/data/modules/betterbuttons.js @@ -47,6 +47,12 @@ function betterbuttons() { 'advanced': true, 'title': 'Add unsticky button to stickied posts.' }); + self.register_setting('addCommentLockbutton', { + type: 'boolean', + default: true, + advanced: false, + title: 'Add comment lock button to comments.', + }); // Bread and buttons var $body = $('body'); @@ -378,6 +384,71 @@ function betterbuttons() { }); }; + self.initCommentLock = function () { + if (TBUtils.isModmail) { + return; + } + if (!TB.utils.isMod) { + return; + } + + function commentLockRun () { + const $comments = $('div.comment:not(.tb-lock-button)'); + TBUtils.forEachChunkedDynamic($comments, processComment); + } + + function processComment (comment) { + const $comment = $(comment); + if (!$comment.hasClass('tb-lock-button')) { + // Add the class so we don't add buttons twice. + $comment.addClass('tb-lock-button'); + let action = 'lock'; + if ($comment.find('.locked-tagline').length > 0) { + action = 'unlock'; + } + + $comment.find('ul.buttons li.toggle:last') + .after(`